|
13 | 13 | use Symfony\Component\Debug\Exception\FatalThrowableError; |
14 | 14 | use Throwable; |
15 | 15 |
|
16 | | -/*final*/ class Worker extends IlluminateWorker |
| 16 | +class Worker extends IlluminateWorker |
17 | 17 | { |
18 | 18 | /** |
19 | 19 | * @var EntityManagerInterface |
@@ -42,33 +42,39 @@ public function __construct( |
42 | 42 | } |
43 | 43 |
|
44 | 44 | /** |
45 | | - * Wrap parent::runJob to make sure we have a good EM. |
| 45 | + * Wrap parent::getNextJob to make sure we have a good EM before processing the next job. |
| 46 | + * This allow us to avoid incrementing the attempts on the job if the worker fails because of the EM. |
46 | 47 | * |
47 | | - * Most exception handling is done in the parent method, so we consider any new |
48 | | - * exceptions to be a result of our setup. |
| 48 | + * Get the next job from the queue connection. |
49 | 49 | * |
50 | | - * @param \Illuminate\Contracts\Queue\Job $job |
51 | | - * @param string $connectionName |
52 | | - * @param WorkerOptions $options |
| 50 | + * @param \Illuminate\Contracts\Queue\Queue $connection |
| 51 | + * @param string $queue |
| 52 | + * @return \Illuminate\Contracts\Queue\Job|null |
53 | 53 | */ |
54 | | - protected function runJob($job, $connectionName, WorkerOptions $options) |
| 54 | + protected function getNextJob($connection, $queue) |
55 | 55 | { |
| 56 | + $exception = null; |
| 57 | + |
56 | 58 | try { |
57 | 59 | $this->assertEntityManagerOpen(); |
58 | 60 | $this->assertEntityManagerClear(); |
59 | 61 | $this->assertGoodDatabaseConnection(); |
60 | | - |
61 | | - parent::runJob($job, $connectionName, $options); |
62 | 62 | } catch (EntityManagerClosedException $e) { |
63 | | - $this->exceptions->report($e); |
64 | | - $this->stop(1); |
| 63 | + $exception = $e; |
65 | 64 | } catch (Exception $e) { |
66 | | - $this->exceptions->report(new QueueSetupException("Error in queue setup while running a job", 0, $e)); |
67 | | - $this->stop(1); |
| 65 | + $exception = new QueueSetupException("Error in queue setup while getting next job", 0, $e); |
68 | 66 | } catch (Throwable $e) { |
69 | | - $this->exceptions->report(new QueueSetupException("Error in queue setup while running a job", 0, new FatalThrowableError($e))); |
70 | | - $this->stop(1); |
| 67 | + $exception = new QueueSetupException("Error in queue setup while getting next job", 0, new FatalThrowableError($e)); |
| 68 | + } |
| 69 | + |
| 70 | + if ($exception) { |
| 71 | + $this->shouldQuit = true; |
| 72 | + $this->exceptions->report($exception); |
| 73 | + |
| 74 | + return null; |
71 | 75 | } |
| 76 | + |
| 77 | + return parent::getNextJob($connection, $queue); |
72 | 78 | } |
73 | 79 |
|
74 | 80 | /** |
|
0 commit comments