File tree Expand file tree Collapse file tree 8 files changed +83
-4
lines changed Expand file tree Collapse file tree 8 files changed +83
-4
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function ucfirst(input) {
3131.task-queued , .task-scheduled {
3232 @apply bg-gray-100 text-gray-500
3333}
34- .task-running {
34+ .task-running , .task-released {
3535 @apply bg-blue-100 text-blue-800
3636}
3737 </style >
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ const titles = {
2727 successful: ' Successful' ,
2828 error: ' An error occurred' ,
2929 failed: ' Failed permanently' ,
30+ released: ' Released' ,
3031}
3132 </script >
3233
@@ -60,6 +61,13 @@ const titles = {
6061 Scheduled: {{ event['scheduled_at'] }} (UTC)
6162 </span >
6263 </div >
64+ <div v-if =" event['delay']" >
65+ <span
66+ class =" bg-gray-200 text-gray-800 text-xs font-medium mr-2 inline-block mb-1 px-1.5 py-0.5 rounded dark:bg-blue-200 dark:text-blue-800"
67+ >
68+ Delay: {{ event['delay'] }} seconds
69+ </span >
70+ </div >
6371 </h3 >
6472 <Popper
6573 :content =" event.datetime"
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ public function release($delay = 0)
128128 }
129129
130130 if (! data_get ($ this ->job , 'internal.errored ' )) {
131- app ('events ' )->dispatch (new JobReleased ($ connection , $ this ));
131+ app ('events ' )->dispatch (new JobReleased ($ connection , $ this , $ delay ));
132132 }
133133 }
134134}
Original file line number Diff line number Diff line change 88use Illuminate \Queue \Events \JobProcessed ;
99use Illuminate \Queue \Events \JobProcessing ;
1010use Illuminate \Support \ServiceProvider as LaravelServiceProvider ;
11+ use Stackkit \LaravelGoogleCloudTasksQueue \Events \JobReleased ;
1112use Stackkit \LaravelGoogleCloudTasksQueue \Events \TaskCreated ;
1213use function Safe \file_get_contents ;
1314use function Safe \json_decode ;
@@ -187,5 +188,13 @@ private function registerDashboard(): void
187188
188189 DashboardService::make ()->markAsFailed ($ event );
189190 });
191+
192+ app ('events ' )->listen (JobReleased::class, function (JobReleased $ event ) {
193+ if (!CloudTasks::dashboardEnabled ()) {
194+ return ;
195+ }
196+
197+ DashboardService::make ()->markAsReleased ($ event );
198+ });
190199 }
191200}
Original file line number Diff line number Diff line change 99use Illuminate \Queue \Events \JobExceptionOccurred ;
1010use Illuminate \Queue \Events \JobFailed ;
1111use Illuminate \Support \Facades \DB ;
12+ use Stackkit \LaravelGoogleCloudTasksQueue \Events \JobReleased ;
1213use function Safe \json_decode ;
1314
1415class DashboardService
@@ -85,6 +86,10 @@ public function markAsSuccessful(string $uuid): void
8586 {
8687 $ task = StackkitCloudTask::findByUuid ($ uuid );
8788
89+ if ($ task ->status === 'released ' ) {
90+ return ;
91+ }
92+
8893 $ task ->status = 'successful ' ;
8994 $ task ->addMetadataEvent ([
9095 'status ' => $ task ->status ,
@@ -135,6 +140,23 @@ public function markAsFailed(JobFailed $event): void
135140 $ task ->save ();
136141 }
137142
143+ public function markAsReleased (JobReleased $ event ): void
144+ {
145+ /** @var CloudTasksJob $job */
146+ $ job = $ event ->job ;
147+
148+ $ task = StackkitCloudTask::findByUuid ($ job ->uuid ());
149+
150+ $ task ->status = 'released ' ;
151+ $ task ->addMetadataEvent ([
152+ 'status ' => $ task ->status ,
153+ 'datetime ' => now ()->utc ()->toDateTimeString (),
154+ 'delay ' => $ event ->delay ,
155+ ]);
156+
157+ $ task ->save ();
158+ }
159+
138160 private function getTaskName (Task $ task ): string
139161 {
140162 /** @var array $decode */
Original file line number Diff line number Diff line change @@ -22,16 +22,25 @@ class JobReleased
2222 */
2323 public Job $ job ;
2424
25+ /**
26+ * The job delay in seconds.
27+ *
28+ * @var int
29+ */
30+ public int $ delay ;
31+
2532 /**
2633 * Create a new event instance.
2734 *
2835 * @param string $connectionName
2936 * @param Job $job
37+ * @param int $delay
3038 * @return void
3139 */
32- public function __construct (string $ connectionName , Job $ job )
40+ public function __construct (string $ connectionName , Job $ job, int $ delay = 0 )
3341 {
3442 $ this ->job = $ job ;
3543 $ this ->connectionName = $ connectionName ;
44+ $ this ->delay = $ delay ;
3645 }
3746}
Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ public static function getCommandProperties(string $command): array
166166 }
167167
168168 if (app ()->bound (Encrypter::class)) {
169- return (array ) unserialize (app (Encrypter::class)->decrypt ($ command ), ['allowed_classes ' => false ]);
169+ return (array ) unserialize (app (Encrypter::class)->decrypt ($ command ), ['allowed_classes ' => [ ' Illuminate\Support\Carbon ' ] ]);
170170 }
171171
172172 return [];
Original file line number Diff line number Diff line change 1010use Stackkit \LaravelGoogleCloudTasksQueue \OpenIdVerificator ;
1111use Stackkit \LaravelGoogleCloudTasksQueue \StackkitCloudTask ;
1212use Tests \Support \FailingJob ;
13+ use Tests \Support \JobThatWillBeReleased ;
1314use Tests \Support \SimpleJob ;
1415
1516class CloudTasksDashboardTest extends TestCase
@@ -413,6 +414,36 @@ public function when_a_job_fails_it_will_be_updated_in_the_dashboard()
413414 );
414415 }
415416
417+ /**
418+ * @test
419+ */
420+ public function when_a_job_is_released_it_will_be_updated_in_the_dashboard ()
421+ {
422+ // Arrange
423+ \Illuminate \Support \Carbon::setTestNow (now ());
424+ CloudTasksApi::fake ();
425+ OpenIdVerificator::fake ();
426+ CloudTasksApi::partialMock ()->shouldReceive ('getRetryConfig ' )->andReturn (
427+ (new RetryConfig ())->setMaxAttempts (3 )
428+ );
429+
430+ $ this ->dispatch (new JobThatWillBeReleased ())->run ();
431+
432+ // Assert
433+ $ task = StackkitCloudTask::firstOrFail ();
434+ $ events = $ task ->getEvents ();
435+
436+ $ this ->assertCount (4 , $ events );
437+ $ this ->assertEquals (
438+ [
439+ 'status ' => 'released ' ,
440+ 'datetime ' => now ()->toDateTimeString (),
441+ 'diff ' => '1 second ago ' ,
442+ ],
443+ $ events [2 ]
444+ );
445+ }
446+
416447 /**
417448 * @test
418449 */
You can’t perform that action at this time.
0 commit comments