Skip to content

Commit

Permalink
Merge pull request #48 from nonanerz/fix_delayed_job
Browse files Browse the repository at this point in the history
fix delayed job with no time set
  • Loading branch information
mcfedr authored Jul 25, 2024
2 parents 11b55bb + 49ea36f commit a7fd4e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public function put(string $name, array $arguments = [], array $options = []): J
$jobTime = new Carbon("+{$options['delay']} seconds", new \DateTimeZone('UTC'));
}

if (!isset($jobTime) || $jobTime < new \DateTime('+30 seconds', new \DateTimeZone('UTC'))) {
if (isset($jobTime) && (!isset($options['force_delay']) || !$options['force_delay'])) {
return $this->queueManagerRegistry->put($name, $arguments, $jobOptions, $jobManager);
}
$executeImmediately = !isset($jobTime) || $jobTime < new \DateTime('+30 seconds', new \DateTimeZone('UTC'));
$executeImmediately = $executeImmediately && (!isset($jobTime) || !isset($options['force_delay']) || !$options['force_delay']);

if ($executeImmediately) {
return $this->queueManagerRegistry->put($name, $arguments, $jobOptions, $jobManager);
}

$job = new DoctrineDelayJob($name, $arguments, $jobOptions, $jobManager, $jobTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@ public function testNonForceDelay(): void

self::assertNotInstanceOf(DoctrineDelayJob::class, $putJob);
}

public function testNonForceDelayWithNoTimeSet(): void
{
$putJob = $this->manager->put('test_worker', [
'argument_a' => 'a',
]);

self::assertNotInstanceOf(DoctrineDelayJob::class, $putJob);
}
}

0 comments on commit a7fd4e5

Please sign in to comment.