Make backup throttling configurable
This commit is contained in:
parent
a7fef8b736
commit
794cf9d9dd
3 changed files with 23 additions and 9 deletions
|
@ -108,12 +108,16 @@ class InitiateBackupService
|
|||
*/
|
||||
public function handle(Server $server, string $name = null, bool $override = false): Backup
|
||||
{
|
||||
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, 10);
|
||||
if ($previous->count() >= 2) {
|
||||
throw new TooManyRequestsHttpException(
|
||||
CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addMinutes(10)),
|
||||
'Only two backups may be generated within a 10 minute span of time.'
|
||||
);
|
||||
$limit = config('backups.throttles.limit');
|
||||
$period = config('backups.throttles.period');
|
||||
if ($period > 0) {
|
||||
$previous = $this->repository->getBackupsGeneratedDuringTimespan($server->id, $period);
|
||||
if ($previous->count() >= $limit) {
|
||||
throw new TooManyRequestsHttpException(
|
||||
CarbonImmutable::now()->diffInSeconds($previous->last()->created_at->addMinutes(10)),
|
||||
sprintf('Only %d backups may be generated within a %d second span of time.', $limit, $period)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the server has reached or exceeded it's backup limit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue