You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry for opening an issue, but I think I've exhausted the solutions I've found in the docs and here in closed issues.
I aim to:
Schedule a job within Kernel.php using the schedule() function.
Execute this job via Horizon with tenant awareness.
I've explored two approaches based on the documentation and discussions in this repository.
Approach 1:
protectedfunctionschedule(Schedule$schedule)
{
Tenant::all()->eachCurrent(function (Tenant$tenant) use ($schedule) {
Log::info('Schedule for tenant: '.$tenant->id);
$schedule->job(newFetchItems($tenant->name))
->name('fetch-items-'.$tenant->id) // unique name for each tenant
->everyMinute();
});
}
// FetchItems:classFetchItemsimplementsShouldQueue
{
publicfunction__construct(string$tenantName = null)
{
// log random number Log::info('Random number: '.rand(1, 1000));
}
// rest of the code
}
Result:
php artisan schedule:run
[2023-11-18 19:02:23] local.INFO: Schedule for tenant: 1
[2023-11-18 19:02:23] local.INFO: Random number: 414
[2023-11-18 19:02:23] local.INFO: Schedule for tenant: 2
[2023-11-18 19:02:23] local.INFO: Random number: 197
[2023-11-18 19:02:23] local.INFO: Schedule for tenant: 3
[2023-11-18 19:02:23] local.INFO: Random number: 322
Running php artisan schedule:run logs the expected information. However, when processed by Horizon, an error occurs stating that the current tenant could not be determined, with no tenantId in the payload. The current tenant could not be determined in a job named Illuminate\Queue\CallQueuedHandler@call. No tenantId was set in the payload.
Approach 2:
I modified the scheduling code as follows:
protectedfunctionschedule(Schedule$schedule)
{
$schedule->job(newFetchItems())
->name('fetch-items')
->withoutOverlapping()
->everyMinute();
}
// FetchItems class as in Approach 1
}
Running php artisan tenants:artisan schedule:run executes correctly, but with Horizon the job seems to be fixed to the first tenant, with the constructor running only once during scheduling. This behaviour is not what I expected as I need the job to be tenant specific.
I'm looking for insight into what might be missing or overlooked in my implementation. Any advice or suggestions would be greatly appreciated. Thank you very much.
The text was updated successfully, but these errors were encountered:
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.
Sorry for opening an issue, but I think I've exhausted the solutions I've found in the docs and here in closed issues.
I aim to:
I've explored two approaches based on the documentation and discussions in this repository.
Approach 1:
Result:
Running php artisan schedule:run logs the expected information. However, when processed by Horizon, an error occurs stating that the current tenant could not be determined, with no tenantId in the payload.
The current tenant could not be determined in a job named Illuminate\Queue\CallQueuedHandler@call. No tenantId was set in the payload.
Approach 2:
I modified the scheduling code as follows:
and php artisan tenants:artisan schedule:run
Result:
Running php artisan tenants:artisan schedule:run executes correctly, but with Horizon the job seems to be fixed to the first tenant, with the constructor running only once during scheduling. This behaviour is not what I expected as I need the job to be tenant specific.
I'm looking for insight into what might be missing or overlooked in my implementation. Any advice or suggestions would be greatly appreciated. Thank you very much.
The text was updated successfully, but these errors were encountered: