From ec5fb43e4890becf7e13dac9b21fee4a0b73417b Mon Sep 17 00:00:00 2001 From: Job Vink Date: Wed, 12 Nov 2025 13:37:58 +0100 Subject: [PATCH 1/3] Add support for job delay in CloudTasksQueue --- src/CloudTasksQueue.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CloudTasksQueue.php b/src/CloudTasksQueue.php index 058da45..835cf20 100644 --- a/src/CloudTasksQueue.php +++ b/src/CloudTasksQueue.php @@ -133,7 +133,13 @@ public function push($job, $data = '', $queue = null) $queue, null, function ($payload, $queue) use ($job) { - return $this->pushRaw($payload, $queue, ['job' => $job]); + $options = ['job' => $job]; + + if (is_object($job) && property_exists($job, 'delay') && $job->delay !== null) { + $options['delay'] = $job->delay; + } + + return $this->pushRaw($payload, $queue, $options); } ); } From 16b5550f72474b6bc57f26df7ec66afdaeefe3e6 Mon Sep 17 00:00:00 2001 From: Job Vink Date: Wed, 12 Nov 2025 13:53:03 +0100 Subject: [PATCH 2/3] fixed linting issues --- src/CloudTasksQueue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CloudTasksQueue.php b/src/CloudTasksQueue.php index 835cf20..be377e8 100644 --- a/src/CloudTasksQueue.php +++ b/src/CloudTasksQueue.php @@ -134,11 +134,11 @@ public function push($job, $data = '', $queue = null) null, function ($payload, $queue) use ($job) { $options = ['job' => $job]; - + if (is_object($job) && property_exists($job, 'delay') && $job->delay !== null) { $options['delay'] = $job->delay; } - + return $this->pushRaw($payload, $queue, $options); } ); From 7631f3dfd7ca0aca072faa9906e2d14105591468 Mon Sep 17 00:00:00 2001 From: Job Vink Date: Fri, 14 Nov 2025 16:23:22 +0100 Subject: [PATCH 3/3] Add tests for job scheduling with delay property in CloudTasksQueue --- tests/QueueTest.php | 36 ++++++++++++++++++++ tests/Support/SimpleJobWithDelayProperty.php | 30 ++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/Support/SimpleJobWithDelayProperty.php diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 1e9110e..54e2176 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -25,6 +25,7 @@ use Tests\Support\JobThatWillBeReleased; use Illuminate\Queue\Events\JobProcessed; use Illuminate\Queue\Events\JobProcessing; +use Tests\Support\SimpleJobWithDelayProperty; use Tests\Support\FailingJobWithExponentialBackoff; use Illuminate\Queue\Events\JobReleasedAfterException; use Stackkit\LaravelGoogleCloudTasksQueue\IncomingTask; @@ -613,4 +614,39 @@ public function task_has_configured_dispatch_deadline(): void return $task->getDispatchDeadline()->getSeconds() === 1800; }); } + + #[Test] + public function it_will_set_the_scheduled_time_when_job_has_delay_property(): void + { + // Arrange + CloudTasksApi::fake(); + Carbon::setTestNow(now()->addDay()); + + // Act + $this->dispatch(Bus::batch([ + new SimpleJobWithDelayProperty(500), + ])); + + // Assert + CloudTasksApi::assertTaskCreated(function (Task $task): bool { + return $task->getScheduleTime()->getSeconds() === now()->addSeconds(500)->timestamp; + }); + } + + #[Test] + public function it_will_not_set_scheduled_time_when_job_delay_property_is_null(): void + { + // Arrange + CloudTasksApi::fake(); + + // Act + $this->dispatch(Bus::batch([ + new SimpleJobWithDelayProperty(null), + ])); + + // Assert + CloudTasksApi::assertTaskCreated(function (Task $task): bool { + return $task->getScheduleTime() === null; + }); + } } diff --git a/tests/Support/SimpleJobWithDelayProperty.php b/tests/Support/SimpleJobWithDelayProperty.php new file mode 100644 index 0000000..64833fa --- /dev/null +++ b/tests/Support/SimpleJobWithDelayProperty.php @@ -0,0 +1,30 @@ +delay = $delay; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + event(new JobOutput('SimpleJobWithDelayProperty:success')); + } +}