22
33namespace  Stackkit \LaravelGoogleCloudTasksQueue ;
44
5+ use  Google \ApiCore \ApiException ;
56use  Google \Cloud \Tasks \V2 \CloudTasksClient ;
67use  Google \Cloud \Tasks \V2 \RetryConfig ;
78use  Illuminate \Bus \Queueable ;
@@ -122,6 +123,24 @@ private function handleTask(array $task): void
122123
123124        $ this loadQueueRetryConfig ($ job
124125
126+         $ taskNamerequest ()->header ('X-Cloudtasks-Taskname ' );
127+         $ fullTaskName$ this client ->taskName (
128+             $ this config ['project ' ],
129+             $ this config ['location ' ],
130+             $ jobgetQueue () ?: $ this config ['queue ' ],
131+             $ taskName
132+         );
133+ 
134+         try  {
135+             $ apiTaskgetTask ($ fullTaskName
136+         } catch  (ApiException $ e
137+             if  (in_array ($ egetStatus (), ['NOT_FOUND ' , 'PRECONDITION_FAILED ' ])) {
138+                 abort (404 );
139+             }
140+ 
141+             throw  $ e
142+         }
143+ 
125144        // If the task has a [X-CloudTasks-TaskRetryCount] header higher than 0, then 
126145        // we know the job was created using an earlier version of the package. This 
127146        // job does not have the attempts tracked internally yet. 
@@ -138,20 +157,7 @@ private function handleTask(array $task): void
138157        // max retry duration has been set. If that duration 
139158        // has passed, it should stop trying altogether. 
140159        if  ($ jobattempts () > 0 ) {
141-             $ taskNamerequest ()->header ('X-Cloudtasks-Taskname ' );
142- 
143-             if  (!is_string ($ taskName
144-                 throw  new  UnexpectedValueException ('Expected task name to be a string. ' );
145-             }
146- 
147-             $ fullTaskName$ this client ->taskName (
148-                 $ this config ['project ' ],
149-                 $ this config ['location ' ],
150-                 $ jobgetQueue () ?: $ this config ['queue ' ],
151-                 $ taskName
152-             );
153- 
154-             $ jobsetRetryUntil (CloudTasksApi::getRetryUntilTimestamp ($ fullTaskName
160+             $ jobsetRetryUntil (CloudTasksApi::getRetryUntilTimestamp ($ apiTask
155161        }
156162
157163        $ jobsetAttempts ($ jobattempts () + 1 );
0 commit comments