From 4c2db0ed3b1115ee4b9834d53ac575afc248ff20 Mon Sep 17 00:00:00 2001 From: Rias Date: Fri, 23 Aug 2024 13:41:28 +0200 Subject: [PATCH] Fix exception --- src/Actions/MakeQueueTenantAwareAction.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Actions/MakeQueueTenantAwareAction.php b/src/Actions/MakeQueueTenantAwareAction.php index 974e2f5..715592f 100644 --- a/src/Actions/MakeQueueTenantAwareAction.php +++ b/src/Actions/MakeQueueTenantAwareAction.php @@ -47,7 +47,21 @@ protected function isTenantAware(JobProcessing|JobRetryRequested $event): bool { $payload = $this->getEventPayload($event); - $command = unserialize($payload['data']['command']); + try { + $command = unserialize($payload['data']['command']); + } catch (\Throwable) { + /** + * We might need the tenant to unserialize jobs as models could + * have global scopes set that require a current tenant to + * be active. bindOrForgetCurrentTenant wil reset it. + */ + if ($tenantId = Context::get($this->currentTenantContextKey())) { + $tenant = app(IsTenant::class)::find($tenantId); + $tenant?->makeCurrent(); + } + + $command = unserialize($payload['data']['command']); + } $job = $this->getJobFromQueueable($command);