Skip to content

Commit

Permalink
Merge pull request #47 from nonanerz/dev
Browse files Browse the repository at this point in the history
allow 5 seconds minimal delay
  • Loading branch information
mcfedr authored Jul 22, 2024
2 parents e7aa12c + 63817cf commit 11b55bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@ This will create a `QueueManager` service named `"mcfedr_queue_manager.delay"`.

* `time` - A `\DateTime` object of when to schedule this job.
* `delay` - Number of seconds from now to schedule this job.
* `force_delay` - A boolean that forces the job to be delayed by the specified number of seconds.
* `manager` - Use a different job processor for this job.
* `manager_options` - Options to pass to the processors `put` method.

#### Note

If `delay` or `time` option is less then 30 seconds the job will be scheduled for immediate execution.
If `delay` or `time` option is less then 30 seconds the job will be scheduled for immediate execution unless the `force_delay` option is set to `true`

#### Tables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function put(string $name, array $arguments = [], array $options = []): J
}

if (!isset($jobTime) || $jobTime < new \DateTime('+30 seconds', new \DateTimeZone('UTC'))) {
return $this->queueManagerRegistry->put($name, $arguments, $jobOptions, $jobManager);
if (isset($jobTime) && (!isset($options['force_delay']) || !$options['force_delay'])) {
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 @@ -224,4 +224,22 @@ public function testNonPersisted(): void

$this->manager->delete($toDelete);
}

public function testForceDelay(): void
{
$putJob = $this->manager->put('test_worker', [
'argument_a' => 'a',
], ['time' => new \DateTime('+5 seconds'), 'force_delay' => true]);

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

public function testNonForceDelay(): void
{
$putJob = $this->manager->put('test_worker', [
'argument_a' => 'a',
], ['time' => new \DateTime('+5 seconds')]);

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

0 comments on commit 11b55bb

Please sign in to comment.