Remove backup and mount repositories

This commit is contained in:
Lance Pioch
2024-03-16 23:01:45 -04:00
parent 9d3a6ae494
commit aa93cd65c1
9 changed files with 41 additions and 132 deletions

View File

@@ -3,10 +3,12 @@
namespace App\Models;
use App\Exceptions\Http\Connection\DaemonConnectionException;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Psr\Http\Message\ResponseInterface;
use Znck\Eloquent\Traits\BelongsToThrough;
@@ -386,4 +388,27 @@ class Server extends Model
throw new DaemonConnectionException($exception);
}
}
/**
* Determines if too many backups have been generated by the server.
*/
public function getBackupsGeneratedDuringTimespan(int $seconds = 600): array|Collection
{
return self::query()
->backups()
->where(fn ($query) => $query->whereNull('completed_at')->orWhere('is_successful', true))
->where('created_at', '>=', now()->subSeconds($seconds))
->withTrashed()
->get();
}
/**
* Returns a query filtering only non-failed backups for a specific server.
*/
public function getNonFailedBackups(): HasMany
{
return $this->backups()->where(
fn ($query) => $query->whereNull('completed_at')->orWhere('is_successful', true)
);
}
}