Skip to content

Commit

Permalink
Adjust bulk request cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean committed Aug 27, 2024
1 parent 6596acc commit 909f905
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config/magento-async.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
return [
'queue' => 'default',

/* Cleanup requests after amount of time (hours) */
'cleanup' => 3,
/* Always cleanup bulk requests after amount of time (hours) */
'cleanup' => 168,
];
13 changes: 12 additions & 1 deletion src/Actions/CleanBulkRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace JustBetter\MagentoAsync\Actions;

use Illuminate\Database\Eloquent\Builder;
use JustBetter\MagentoAsync\Contracts\CleansBulkRequests;
use JustBetter\MagentoAsync\Enums\OperationStatus;
use JustBetter\MagentoAsync\Models\BulkRequest;

class CleanBulkRequests implements CleansBulkRequests
Expand All @@ -13,7 +15,16 @@ public function clean(): void
$cleanupHours = config('magento-async.cleanup');

BulkRequest::query()
->where('created_at', '<', now()->subHours($cleanupHours))
// Delete where there are no more operations with a non-final status
->where(function (Builder $query) use ($cleanupHours): void {

Check failure on line 19 in src/Actions/CleanBulkRequests.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - ubuntu-latest

Anonymous function has an unused use $cleanupHours.

Check failure on line 19 in src/Actions/CleanBulkRequests.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - ubuntu-latest

Anonymous function has an unused use $cleanupHours.
$query->whereDoesntHave('operations', function (Builder $query): void {
$query
->whereNull('status')
->orWhere('status', '=', OperationStatus::Open);
})->orWhere('created_at', '<', now()->subHour()); // Never delete within an hour
})
// Always delete after 7 days
->orWhere('created_at', '<', now()->subHours($cleanupHours))
->delete();
}

Expand Down

0 comments on commit 909f905

Please sign in to comment.