@@ -82,41 +82,35 @@ public function size(): int
8282 */
8383 public function consume (): ?DbJob
8484 {
85- $ attempts = 0 ;
86-
87- do {
88- $ jobRaw = $ this ->addBuilderConditions ($ this ->getQueryBuilder ())
89- ->orderBy ('job_id ' , Order::ORDER_ASC )
90- ->limit (1 )
91- ->fetchOne ();
92-
93- if (null === $ jobRaw ) {
94- return null ;
95- }
96-
97- // Lock
98- $ affected = $ this ->getQueryBuilder ()
99- ->whereEquals (
100- array_filter (
101- $ jobRaw ,
102- fn ($ k ) => in_array (
103- $ k ,
104- ['job_id ' , 'queue ' , 'availability_time ' , 'attempts ' , 'lock_time ' ]
105- ),
106- ARRAY_FILTER_USE_KEY
107- )
85+ $ jobRaw = $ this ->addBuilderConditions ($ this ->getQueryBuilder ())
86+ ->orderBy ('job_id ' , Order::ORDER_ASC )
87+ ->limit (1 )
88+ ->fetchOne (true );
89+
90+ if (null === $ jobRaw ) {
91+ return null ;
92+ }
93+
94+ // Lock
95+ $ affected = $ this ->getQueryBuilder ()
96+ ->whereEquals (
97+ array_filter (
98+ $ jobRaw ,
99+ fn ($ k ) => in_array (
100+ $ k ,
101+ ['job_id ' , 'queue ' , 'availability_time ' , 'attempts ' , 'lock_time ' ]
102+ ),
103+ ARRAY_FILTER_USE_KEY
108104 )
109- ->update ($ updatedData = [
110- 'lock_time ' => $ this ->now ()->format ('Y-m-d H:i:s ' ),
111- 'attempts ' => ($ jobRaw ['attempts ' ] ?? 0 ) + 1 ,
112- ]);
113-
114- if ($ affected === 1 ) {
115- return $ this ->createJob (array_replace ($ jobRaw , $ updatedData ));
116- }
105+ )
106+ ->update ($ updatedData = [
107+ 'lock_time ' => $ this ->now ()->format ('Y-m-d H:i:s ' ),
108+ 'attempts ' => ($ jobRaw ['attempts ' ] ?? 0 ) + 1 ,
109+ ]);
117110
118- $ attempts ++;
119- } while ($ attempts < 5 );
111+ if ($ affected === 1 ) {
112+ return $ this ->createJob (array_replace ($ jobRaw , $ updatedData ));
113+ }
120114
121115 return null ;
122116 }
0 commit comments