Skip to content

Commit 93d1bdc

Browse files
committed
Release again if database deadlock occurred
1 parent 8673a71 commit 93d1bdc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ public function __construct(
5151
$this->message = $message;
5252
}
5353

54+
/**
55+
* Fire the job.
56+
* @return void
57+
* @throws Exception
58+
*/
59+
public function fire()
60+
{
61+
$payload = $this->payload();
62+
63+
list($class, $method) = $this->parseJob($payload['job']);
64+
65+
$this->instance = $this->resolve($class);
66+
67+
try {
68+
$this->instance->{$method}($this, $payload['data']);
69+
} catch (Exception $exception) {
70+
if (
71+
$this->causedByDeadlock($exception) ||
72+
Str::contains($exception->getMessage(), ['detected deadlock'])
73+
) {
74+
sleep(2);
75+
$this->fire();
76+
return;
77+
}
78+
79+
throw $exception;
80+
}
81+
}
82+
5483
/**
5584
* Get the number of times the job has been attempted.
5685
*

0 commit comments

Comments
 (0)