Skip to content

Commit 6b2dfa3

Browse files
committed
added force_delay option
1 parent 9a1dfa9 commit 6b2dfa3

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,13 @@ This will create a `QueueManager` service named `"mcfedr_queue_manager.delay"`.
254254

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

260261
#### Note
261262

262-
If `delay` or `time` option is less then 30 seconds the job will be scheduled for immediate execution.
263+
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`
263264

264265
#### Tables
265266

src/Mcfedr/QueueManagerBundle/Manager/DoctrineDelayQueueManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public function put(string $name, array $arguments = [], array $options = []): J
5555
$jobTime = new Carbon("+{$options['delay']} seconds", new \DateTimeZone('UTC'));
5656
}
5757

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

6264
$job = new DoctrineDelayJob($name, $arguments, $jobOptions, $jobManager, $jobTime);

tests/Mcfedr/QueueManagerBundle/Tests/Manager/DoctrineDelayQueueManagerTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function testPutWithNotSignificantDelayAndTimeInPast(\DateTime $jobTime):
122122
public function providePutWithNotSignificantDelayAndTimeInPastCases(): iterable
123123
{
124124
return [
125-
[new \DateTime('+4 seconds')],
125+
[new \DateTime('+12 seconds')],
126126
[new \DateTime('-12 seconds')],
127127
];
128128
}
@@ -224,4 +224,22 @@ public function testNonPersisted(): void
224224

225225
$this->manager->delete($toDelete);
226226
}
227+
228+
public function testForceDelay(): void
229+
{
230+
$putJob = $this->manager->put('test_worker', [
231+
'argument_a' => 'a',
232+
], ['time' => new \DateTime('+5 seconds'), 'force_delay' => true]);
233+
234+
self::assertInstanceOf(DoctrineDelayJob::class, $putJob);
235+
}
236+
237+
public function testNonForceDelay(): void
238+
{
239+
$putJob = $this->manager->put('test_worker', [
240+
'argument_a' => 'a',
241+
], ['time' => new \DateTime('+5 seconds')]);
242+
243+
self::assertNotInstanceOf(DoctrineDelayJob::class, $putJob);
244+
}
227245
}

0 commit comments

Comments
 (0)