Files
device-management/routes/console.php
T
Wian Drs 60946ddf37
tests / ci (push) Has been cancelled
update lisensi prosess
2026-08-25 13:43:55 +07:00

44 lines
2.3 KiB
PHP

<?php
use App\Enums\LicenseStatus;
use App\Jobs\SyncDeviceBaseCredential;
use App\Jobs\SyncDeviceUser;
use App\Models\Device;
use App\Models\DeviceUserAssignment;
use App\Models\License;
use App\Services\LicenseEntitlementService;
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 {
License::withoutGlobalScope('tenant')->where('status', LicenseStatus::Active->value)->where('expires_at', '<=', now())->get()->each(fn (License $license) => $license->update(['status' => $license->grace_until?->isFuture() ? LicenseStatus::Grace : LicenseStatus::Expired]));
License::withoutGlobalScope('tenant')->where('status', LicenseStatus::Grace->value)->where('grace_until', '<=', now())->update(['status' => LicenseStatus::Expired]);
})->everyMinute()->name('update-license-statuses')->withoutOverlapping();
Schedule::call(function (): void {
DeviceUserAssignment::withoutGlobalScope('tenant')->where('sync_status', 'pending')->orderBy('last_attempted_at')->limit(100)->get()->each(function (DeviceUserAssignment $assignment): void {
if (! app(LicenseEntitlementService::class)->allowsUse($assignment->tenant_id)) {
return;
}
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 (! app(LicenseEntitlementService::class)->allowsUse($device->tenant_id)) {
return;
}
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();