From 78b378a80490999458912f3aee40f10aa80b734c Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Mon, 20 May 2024 10:34:56 -0400 Subject: [PATCH] Sure queue TTR is set to 15m --- src/Helper.php | 7 +++---- src/runtime/event/CliHandler.php | 11 +++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Helper.php b/src/Helper.php index 10bb7da..ebeb15b 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -7,6 +7,7 @@ use craft\cloud\fs\BuildArtifactsFs; use craft\cloud\Helper as CloudHelper; use craft\cloud\queue\SqsQueue; +use craft\cloud\runtime\event\CliHandler; use craft\db\Table; use craft\helpers\App; use craft\helpers\ConfigHelper; @@ -126,14 +127,12 @@ public static function modifyConfig(array &$config, string $appType): void }; $config['components']['queue'] = function() { - $ttr = Module::getInstance()->getConfig()->getMaxSeconds() - 1; - return Craft::createObject([ 'class' => CraftQueue::class, - 'ttr' => $ttr, + 'ttr' => CliHandler::maxExecutionSeconds(), 'proxyQueue' => Module::getInstance()->getConfig()->useQueue ? [ 'class' => SqsQueue::class, - 'ttr' => $ttr, + 'ttr' => CliHandler::maxExecutionSeconds(), 'url' => Module::getInstance()->getConfig()->sqsUrl, 'region' => Module::getInstance()->getConfig()->getRegion(), ] : null, diff --git a/src/runtime/event/CliHandler.php b/src/runtime/event/CliHandler.php index 5d0fad9..5c59644 100644 --- a/src/runtime/event/CliHandler.php +++ b/src/runtime/event/CliHandler.php @@ -4,7 +4,6 @@ use Bref\Context\Context; use Bref\Event\Handler; -use craft\cloud\Module; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Exception\ProcessTimedOutException; use Symfony\Component\Process\Process; @@ -12,7 +11,8 @@ class CliHandler implements Handler { - public const MAX_EXECUTION_BUFFER_SECONDS = 5; + public const MAX_EXECUTION_SECONDS = 900; + public const MAX_EXECUTION_BUFFER_SECONDS = 3; public ?Process $process = null; protected string $scriptPath = '/var/task/craft'; protected ?float $totalRunningTime = null; @@ -80,8 +80,11 @@ public function getTotalRunningTime(): float public function shouldRetry(): bool { - $diff = Module::getInstance()->getConfig()->getMaxSeconds() - $this->getTotalRunningTime(); + return $this->getTotalRunningTime() < static::maxExecutionSeconds(); + } - return $diff > static::MAX_EXECUTION_BUFFER_SECONDS; + public static function maxExecutionSeconds(): int + { + return static::MAX_EXECUTION_SECONDS - self::MAX_EXECUTION_BUFFER_SECONDS; } }