laravel-multitenancy: Queue retry fails for tenant aware jobs

Hello,

Forgive me if I’m wrong, but I think that there is an issue when trying to retry failed tenant aware jobs.

  • configuration queues_are_tenant_aware_by_default set to true
  • Not trying to add the jobs into the tenant databases (most of issues are related to this)
  1. Typical failed job retry

php artisan queue:retry ID fails because it can not unserialize the payload command at \Illuminate\Queue\Console\RetryCommand::refreshRetryUntil. Switch tenant database never called…

  1. Retry job via tenant aware command - NO tenant specified

php artisan tenants:artisan "queue:retry ID" partially works but it’s executed for every tenant which means that command will succeed only once and will fail for all other tenants.

  1. Retry job via tenant aware command - tenant specified

php artisan tenants:artisan "queue:retry ID" --tenant=TENANT_ID works as it should but this means that every time we should check for the TENANT_ID at the payload which is nasty 😉. When you have a lot jobs failed it’s even worse…

Possible solution could be if we have tenant aware queue retry command that could extend \Illuminate\Queue\Console\RetryCommand and wrap retryJob parents method with set/forget tenant calls if it’s a tenant aware job of course.

What do you think about this solution? Any better ideas?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Merged 🥳

@aginev, I can confirm the bug: I’m working to a fix. Thanks.

@aginev yes, submit the PR but please fix the line

$tenantId = $this->getEventPayload($event)['tenantId'];

with

$tenantId = $this->getEventPayload($event)['tenantId'] ?? null;

Thanks for your work on it.

Nice, well done 👍