I'm a bit perplexed about an issue I'm having with one of my commands.
I've got a command that runs every Monday morning, that loops through my subscribers, and for each one dispatches a job to my queue that syncs their data with a CRM.
public function handle()
{
Log::info('Starting Sync...');
// Get Active Subscibers
$subscribers = Example::get();
Log::info('Found ' . $subscribers->count() . ' subscribers.');
$count = 0;
foreach ($subscribers as $subscriber)
{
Log::info('Syncing data for subscriber: ' . $subscriber->name . '. Dispatching job to the queue...');
ExampleSyncJob::dispatch($subscriber)->delay(now()->addMinutes($count));
$count++;
}
Log::info('Subscription Sync Command completed.');
}
This runs fine, in my laravel log (I have daily logs set up) I can see all of the log entries from there, all good.
However - something seems to be happening within the job that changes the log file to be owned by root.
My job file looks like this;
public function handle(): void
{
Log::info('Starting job with subscription ID ' . $subscription->id);
....
// Do all of the processing
Log::info('Job completed.');
}
But none of the logs from within the jobs themselves are being written to my log file, and the jobs aren't running, but there's nothing in my error log - I think because the application doesn't have permission to write to the log any more.
When I SSH onto my server, today's laravel log is owned by root (rather than forge). So the job is doing something to change the ownership of the log file, which is in turn causing errors because my logs cannot be written to the log file.
However - when I SSH onto the server and run the command manually php artisan app:sync-data it works absolutely fine and all functions correctly, and the log file owner doesn't get updated. So I'm not sure why when I trigger it from my application it's causing this permissions error.
Also FYI; my console.php file has this which triggers the command:
// Runs Every Monday Morning At 2am
Schedule::command(SyncSubscriberData::class)
->weeklyOn(1, '02:00')
->environments(['production']);
Running Laravel 12.21