File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -103,11 +103,31 @@ public function timeoutAt(): ?int
103103
104104    public  function  delete (): void 
105105    {
106+         // Laravel automatically calls delete() after a job is processed successfully. However, this is 
107+         // not what we want to happen in Cloud Tasks because Cloud Tasks will also delete the task upon 
108+         // a 200 OK status, which means a task is deleted twice, possibly resulting in errors. So if the 
109+         // task was processed successfully (no errors or failures) then we will not delete the task 
110+         // manually and will let Cloud Tasks do it. 
111+         $ successful
112+             // If the task has failed, we should be able to delete it permanently 
113+             $ this hasFailed () === false 
114+             // If the task has errored, it should be released, which in process deletes the errored task 
115+             && $ this hasError () === false ;
116+ 
117+         if  ($ successful
118+             return ;
119+         }
120+ 
106121        parent ::delete ();
107122
108123        $ this cloudTasksQueue ->delete ($ this 
109124    }
110125
126+     public  function  hasError (): bool 
127+     {
128+         return  data_get ($ this job , 'internal.errored ' ) === true ;
129+     }
130+ 
111131    public  function  release ($ delay0 )
112132    {
113133        parent ::release ();
Original file line number Diff line number Diff line change @@ -242,7 +242,7 @@ public function jobs_can_be_released()
242242
243243        // Assert 
244244        Event::assertNotDispatched ($ this getJobReleasedAfterExceptionEvent ());
245-         CloudTasksApi::assertDeletedTaskCount (1 ); 
245+         CloudTasksApi::assertDeletedTaskCount (0 );  // it returned 200 OK so we dont delete it, but Google does 
246246        $ releasedJobnull ;
247247        Event::assertDispatched (JobReleased::class, function  (JobReleased $ eventuse  (&$ releasedJob
248248            $ releasedJob$ eventjob ;
@@ -257,7 +257,7 @@ public function jobs_can_be_released()
257257
258258        $ this runFromPayload ($ releasedJobgetRawBody ());
259259
260-         CloudTasksApi::assertDeletedTaskCount (2 );
260+         CloudTasksApi::assertDeletedTaskCount (0 );
261261        CloudTasksApi::assertTaskCreated (function  (Task $ task
262262            $ body$ taskgetHttpRequest ()->getBody ();
263263            $ decodedjson_decode ($ bodytrue );
@@ -476,6 +476,6 @@ public function test_ignoring_jobs_with_deleted_models()
476476
477477        // Act 
478478        Log::assertLogged ('UserJob:John ' );
479-         CloudTasksApi::assertTaskDeleted ($ jobtask ->getName ());
479+         CloudTasksApi::assertTaskNotDeleted ($ jobtask ->getName ());
480480    }
481481}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments