@@ -184,18 +184,24 @@ protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts
184
184
*
185
185
* @param string $queue
186
186
* @return \Illuminate\Contracts\Queue\Job|null
187
+ * @throws \Exception|\Throwable
187
188
*/
188
189
public function pop ($ queue = null )
189
190
{
190
191
$ queue = $ this ->getQueue ($ queue );
191
192
192
- $ this ->database ->beginTransaction ();
193
+ try {
194
+ $ this ->database ->beginTransaction ();
193
195
194
- if ($ job = $ this ->getNextAvailableJob ($ queue )) {
195
- return $ this ->marshalJob ($ queue , $ job );
196
- }
196
+ if ($ job = $ this ->getNextAvailableJob ($ queue )) {
197
+ return $ this ->marshalJob ($ queue , $ job );
198
+ }
197
199
198
- $ this ->database ->commit ();
200
+ $ this ->database ->commit ();
201
+ } catch (\Throwable $ ex ) {
202
+ $ this ->database ->rollBack ();
203
+ throw $ ex ;
204
+ }
199
205
}
200
206
201
207
/**
@@ -288,16 +294,15 @@ protected function markJobAsReserved($job)
288
294
* @param string $queue
289
295
* @param string $id
290
296
* @return void
297
+ * @throws \Exception|\Throwable
291
298
*/
292
299
public function deleteReserved ($ queue , $ id )
293
300
{
294
- $ this ->database ->beginTransaction ();
295
-
296
- if ($ this ->database ->table ($ this ->table )->lockForUpdate ()->find ($ id )) {
297
- $ this ->database ->table ($ this ->table )->where ('id ' , $ id )->delete ();
298
- }
299
-
300
- $ this ->database ->commit ();
301
+ $ this ->database ->transaction (function () use ($ queue , $ id ) {
302
+ if ($ this ->database ->table ($ this ->table )->lockForUpdate ()->find ($ id )) {
303
+ $ this ->database ->table ($ this ->table )->where ('id ' , $ id )->delete ();
304
+ }
305
+ });
301
306
}
302
307
303
308
/**
0 commit comments