30 lines
1.5 KiB
PHP
30 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Jobs\SyncDeviceBaseCredential;
|
|
use App\Jobs\SyncDeviceUser;
|
|
use App\Models\Device;
|
|
use App\Models\DeviceUserAssignment;
|
|
use Illuminate\Foundation\Inspiring;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\Schedule;
|
|
|
|
Artisan::command('inspire', function () {
|
|
$this->comment(Inspiring::quote());
|
|
})->purpose('Display an inspiring quote');
|
|
|
|
Schedule::call(function (): void {
|
|
DeviceUserAssignment::withoutGlobalScope('tenant')->where('sync_status', 'pending')->orderBy('last_attempted_at')->limit(100)->get()->each(function (DeviceUserAssignment $assignment): void {
|
|
if (DeviceUserAssignment::withoutGlobalScope('tenant')->whereKey($assignment->id)->where('sync_status', 'pending')->update(['sync_status' => 'queued'])) {
|
|
SyncDeviceUser::dispatch($assignment->tenant_id, $assignment->id);
|
|
}
|
|
});
|
|
})->everyFiveMinutes()->name('retry-pending-device-users')->withoutOverlapping();
|
|
|
|
Schedule::call(function (): void {
|
|
Device::withoutGlobalScope('tenant')->where('base_sync_status', 'pending')->orderBy('base_sync_attempted_at')->limit(100)->get()->each(function (Device $device): void {
|
|
if (Device::withoutGlobalScope('tenant')->whereKey($device->id)->where('base_sync_status', 'pending')->update(['base_sync_status' => 'queued'])) {
|
|
SyncDeviceBaseCredential::dispatch($device->tenant_id, $device->id);
|
|
}
|
|
});
|
|
})->everyFiveMinutes()->name('retry-pending-base-credentials')->withoutOverlapping();
|