From 1208f2439fb14abcecd39439b4dca7711f122935 Mon Sep 17 00:00:00 2001 From: Ronald A Richardson Date: Mon, 20 Apr 2026 22:16:30 -0400 Subject: [PATCH] feat: schedule sandbox:sync to run hourly Registers the sandbox:sync Artisan command in the CoreServiceProvider scheduler so that production users and companies are periodically mirrored into the sandbox database without any manual intervention. Hourly cadence is chosen as a sensible default: - New users/companies created in production become available in sandbox within at most one hour, keeping the sandbox reasonably fresh. - The command is lightweight (upserts only; no heavy data transforms) so running it every hour does not impose meaningful DB load. - withoutOverlapping() ensures a long-running sync cannot queue up multiple concurrent instances if the scheduler fires while a previous run is still in progress. This complements the on-demand sync added to ApiCredentialController (which handles the immediate FK-constraint case at key-creation time) by ensuring the sandbox stays broadly consistent with production over time for all other sandbox operations. --- src/Providers/CoreServiceProvider.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Providers/CoreServiceProvider.php b/src/Providers/CoreServiceProvider.php index e3330a8..b04e2dd 100644 --- a/src/Providers/CoreServiceProvider.php +++ b/src/Providers/CoreServiceProvider.php @@ -165,6 +165,13 @@ public function boot() $schedule->command('purge:scheduled-task-logs --force --no-interaction --days 1')->twiceDaily(1, 13); $schedule->command('telemetry:ping')->daily(); $schedule->job(new \Fleetbase\Jobs\MaterializeSchedulesJob())->dailyAt('01:00')->name('materialize-schedules')->withoutOverlapping(); + // Keep sandbox users/companies in sync with production so that + // test-mode API key creation (and other sandbox operations) never + // fail due to missing foreign-key referenced rows. Hourly cadence + // is a good balance: frequent enough that new users/companies are + // available in sandbox within an hour of being created in + // production, but infrequent enough to avoid unnecessary DB load. + $schedule->command('sandbox:sync')->hourly()->name('sandbox-sync')->withoutOverlapping(); }); $this->registerObservers(); $this->registerExpansionsFrom();