Skip to content

Commit

Permalink
DE-106539 Fixes for make max delay in seconds configurable (#99)
Browse files Browse the repository at this point in the history
dorrogeray authored Jul 18, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8f8e878 commit 19a9a3e
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Queue/AWSSQS/SqsConsumer.php
Original file line number Diff line number Diff line change
@@ -148,7 +148,11 @@ private function executeJob(SqsMessage $message): JobExecutionStatus

if ($timeRemainsInSeconds > 0) {
$this->logSqsDelayJob($job, $timeRemainsInSeconds);
$this->queueManager->pushDelayed($job, $timeRemainsInSeconds);
$this->queueManager->pushDelayed(
$job,
$timeRemainsInSeconds,
SqsQueueManager::MAX_DELAY_IN_SECONDS,
);

return JobExecutionStatus::DELAYED_NOT_PLANNED_YET;
}
10 changes: 5 additions & 5 deletions src/Queue/AWSSQS/SqsQueueManager.php
Original file line number Diff line number Diff line change
@@ -40,13 +40,13 @@ class SqsQueueManager implements QueueManagerInterface

public const CONSUME_LOOP_ITERATIONS_NO_LIMIT = -1;

// SQS allows maximum message delay of 15 minutes
public const MAX_DELAY_IN_SECONDS = 15 * 60;

private const WAIT_TIME_SECONDS = 'WaitTimeSeconds';

private const DELAY_SECONDS = 'DelaySeconds';

// SQS allows maximum message delay of 15 minutes
private const MAX_DELAY_IN_SECONDS = 15 * 60;

private string $s3BucketName;

private SqsClientFactoryInterface $sqsClientFactory;
@@ -240,8 +240,8 @@ public function pushDelayedWithMilliseconds(JobInterface $job, int $delayInMilli
public function pushDelayed(JobInterface $job, int $delayInSeconds, int $maxDelayInSeconds = self::MAX_DELAY_IN_SECONDS): void
{
assert(
$maxDelayInSeconds > 0,
'Argument $maxDelayInSeconds must be greater than 0',
$maxDelayInSeconds >= 0,
'Argument $maxDelayInSeconds must be greater or equal to 0',
);

$prefixedQueueName = $this->getPrefixedQueueName($job->getJobDefinition()->getQueueName());
8 changes: 7 additions & 1 deletion src/Queue/QueueManagerInterface.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,13 @@ public function consumeMessages(callable $consumer, string $queueName, array $pa
public function push(JobInterface $job): void;


public function pushDelayed(JobInterface $job, int $delayInSeconds): void;
/**
* @param int $maxDelayInSeconds This parameter can be used to override the default maximum delay before using
* delayed job scheduler (if one is configured). This can be useful for
* implementation of automated tests & synthetic monitoring of delayed job
* scheduler on live environments while maintaining quick feedback loop.
*/
public function pushDelayed(JobInterface $job, int $delayInSeconds, int $maxDelayInSeconds): void;


public function pushDelayedWithMilliseconds(JobInterface $job, int $delayInMilliseconds): void;
3 changes: 2 additions & 1 deletion tests/Queue/AWSSQS/SqsConsumerTest.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use BE\QueueManagement\Queue\AWSSQS\MessageDeduplication\MessageDeduplicationDisabled;
use BE\QueueManagement\Queue\AWSSQS\SqsConsumer;
use BE\QueueManagement\Queue\AWSSQS\SqsMessage;
use BE\QueueManagement\Queue\AWSSQS\SqsQueueManager;
use BE\QueueManagement\Queue\JobExecutionStatus;
use BE\QueueManagement\Queue\QueueManagerInterface;
use BrandEmbassy\DateTime\FrozenDateTimeImmutableFactory;
@@ -319,7 +320,7 @@ public function testDelayJobWithExecutionPlannedAt(DateTimeImmutable $executionP
->andReturn($exampleJob);

$this->queueManagerMock->expects('pushDelayed')
->with($exampleJob, $expectedDelay);
->with($exampleJob, $expectedDelay, SqsQueueManager::MAX_DELAY_IN_SECONDS);

$this->sqsClientMock->expects('deleteMessage')
->with([

0 comments on commit 19a9a3e

Please sign in to comment.