Skip to content

Commit

Permalink
Sure queue TTR is set to 15m
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed May 20, 2024
1 parent 72f9997 commit 78b378a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/runtime/event/CliHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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;
use yii\base\Exception;

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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 78b378a

Please sign in to comment.