init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\SyncCafeBazaarAppAction;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Queue\Middleware\RateLimited;
|
||||
use Throwable;
|
||||
|
||||
class SyncCafeBazaarApp implements ShouldBeUnique, ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 8;
|
||||
|
||||
public int $timeout = 300;
|
||||
|
||||
public int $uniqueFor = 600;
|
||||
|
||||
public function __construct(
|
||||
public readonly int $mobileAppId,
|
||||
public readonly bool $force = false,
|
||||
) {}
|
||||
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return (string) $this->mobileAppId;
|
||||
}
|
||||
|
||||
/** @return array<int, int> */
|
||||
public function backoff(): array
|
||||
{
|
||||
return [60, 300, 900];
|
||||
}
|
||||
|
||||
/** @return array<int, object> */
|
||||
public function middleware(): array
|
||||
{
|
||||
return [(new RateLimited('cafe-bazaar-sync'))->releaseAfter(60)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(SyncCafeBazaarAppAction $sync): void
|
||||
{
|
||||
$app = MobileApp::query()->find($this->mobileAppId);
|
||||
|
||||
if ($app === null || (! $app->bazaar_sync_enabled && ! $this->force)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sync->execute($app, $this->force);
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
{
|
||||
MobileApp::query()->whereKey($this->mobileAppId)->update([
|
||||
'bazaar_sync_status' => 'failed',
|
||||
'bazaar_last_synced_at' => now(),
|
||||
'bazaar_sync_error' => $exception?->getMessage() ?? 'The Bazaar synchronization job failed.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user