@@ -99,10 +99,12 @@ public function size(string $queue): int
9999 *
100100 * @param ?string $queue
101101 * @return void
102+ * @throws \ErrorException
102103 */
103104 public function run (?string $ queue = null ): void
104105 {
105106 $ this ->sleep ($ this ->sleep ?? 5 );
107+ $ message = null ;
106108
107109 try {
108110 $ result = $ this ->sqs ->receiveMessage ([
@@ -130,31 +132,31 @@ public function run(?string $queue = null): void
130132 error_log ($ e ->getMessage ());
131133 app ('logger ' )->error ($ e ->getMessage (), $ e ->getTrace ());
132134
133- if (isset ($ message )) {
134- cache (
135- "job:failed: " . $ message ["ReceiptHandle " ],
136- $ message ["Body " ]
137- );
135+ if (!$ message ) {
136+ $ this ->sleep (1 );
137+ return ;
138138 }
139139
140+ cache ("job:failed: " . $ message ["ReceiptHandle " ], $ message ["Body " ]);
141+
140142 // Check if producer has been loaded
141143 if (!isset ($ producer )) {
142144 $ this ->sleep (1 );
143145 return ;
144146 }
145147
146148 // Execute the onException method for notify the producer
147- // and let developper to decide if the job should be delete
149+ // and let developer decide if the job should be deleted
148150 $ producer ->onException ($ e );
149151
150- // Check if the job should be delete
152+ // Check if the job should be deleted
151153 if ($ producer ->jobShouldBeDelete ()) {
152- $ result = $ this ->sqs ->deleteMessage ([
154+ $ this ->sqs ->deleteMessage ([
153155 'QueueUrl ' => $ this ->config ["url " ],
154156 'ReceiptHandle ' => $ message ['ReceiptHandle ' ]
155157 ]);
156158 } else {
157- $ result = $ this ->sqs ->changeMessageVisibilityBatch ([
159+ $ this ->sqs ->changeMessageVisibilityBatch ([
158160 'QueueUrl ' => $ this ->config ["url " ],
159161 'Entries ' => [
160162 'Id ' => $ producer ->getId (),
@@ -163,6 +165,7 @@ public function run(?string $queue = null): void
163165 ],
164166 ]);
165167 }
168+
166169 $ this ->sleep (1 );
167170 }
168171 }
0 commit comments