-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Laravel Scheduler with Multitenancy #103
Comments
Hi @LukeAbell, are you sure that are you doing everything well? See my example here: Please post your code. Thank you |
@masterix21 @freekmurze The issue only occurs when using |
@freekmurze The issue also affects all of the Mailcoach commands. Turning them into Jobs works. |
@LukeAbell, thanks for your issue. I'm working over the solution, and in the next days, I will release the PR to fix it. In the meanwhile, if you like to apply a temporary solution, you can use this trait with your tenant-aware commands: trait IsTenantAware
{
protected function execute(InputInterface $input, OutputInterface $output)
{
$tenantIds = Arr::wrap($this->option('tenant'));
return Tenant::query()
->when(! blank($tenantIds), fn ($query) => $query->whereIn('id', $tenantIds))
->cursor()
->map(fn ($tenant) => $tenant->execute(fn () => (int) $this->laravel->call([$this, 'handle'])))
->sum();
}
} Finally, change your command signatures appending |
@masterix21 thank you!! |
I forgot to say that you could change your schedule method as follow: protected function schedule(Schedule $schedule)
{
$schedule->command('tenant:aware:command');
} And you could call only php artisan schedule:run Thanks |
@LukeAbell the fix has been released. |
@masterix21 thank you!! |
Running
php artisan tenants:artisan schedule:run
loops through the tenants and runs the scheduled commands but Tenant::current() is null. I think I've narrowed this down to the scheduler calling an artisan command in a forked process which recallsphp artisan XXX
with whatever the command is (which bypasses the multi-tenancy call).Is there a way to make the scheduler tenant aware like the package currently does with queues?
Thanks!
The text was updated successfully, but these errors were encountered: