Add 7-day job TTL for functions queue

Set jobTTL to 7 days for FUNCTIONS_QUEUE_NAME using a match expression
for easy extensibility to other queues in the future.
This commit is contained in:
Chirag Aggarwal
2026-02-03 09:03:03 +05:30
parent f648d82c8c
commit f15e9eb356
2 changed files with 29 additions and 2 deletions
+27 -1
View File
@@ -23,6 +23,7 @@ class Event
public const FUNCTIONS_QUEUE_NAME = 'v1-functions';
public const FUNCTIONS_CLASS_NAME = 'FunctionsV1';
public const FUNCTIONS_QUEUE_TTL = 60 * 60 * 24 * 7; // 7 days
public const STATS_RESOURCES_QUEUE_NAME = 'v1-stats-resources';
public const STATS_RESOURCES_CLASS_NAME = 'StatsResourcesV1';
@@ -65,6 +66,8 @@ class Event
/** @var bool Non-critical events will not throw an exception when enqueuing of the event fails. */
protected bool $critical = true;
protected int $ttl = 0;
/**
* @param Publisher $publisher
* @return void
@@ -114,6 +117,29 @@ class Event
return $this->queue;
}
/**
* Set TTL (time-to-live) for jobs in this queue.
*
* @param int $ttl TTL in seconds
* @return static
*/
public function setTTL(int $ttl): static
{
$this->ttl = $ttl;
return $this;
}
/**
* Get TTL (time-to-live) for jobs in this queue.
*
* @return int
*/
public function getTTL(): int
{
return $this->ttl;
}
/**
* Set event name used for this event.
* @param string $event
@@ -369,7 +395,7 @@ class Event
}
/** The getter is required since events like Databases need to override the queue name depending on the project */
$queue = new Queue($this->getQueue());
$queue = new Queue($this->getQueue(), 'utopia-queue', $this->getTTL());
// Merge the base payload with any trimmed values
$payload = array_merge($this->preparePayload(), $this->trimPayload());
+2 -1
View File
@@ -27,7 +27,8 @@ class Func extends Event
$this
->setQueue(System::getEnv('_APP_FUNCTIONS_QUEUE_NAME', Event::FUNCTIONS_QUEUE_NAME))
->setClass(System::getEnv('_APP_FUNCTIONS_CLASS_NAME', Event::FUNCTIONS_CLASS_NAME));
->setClass(System::getEnv('_APP_FUNCTIONS_CLASS_NAME', Event::FUNCTIONS_CLASS_NAME))
->setTTL(Event::FUNCTIONS_QUEUE_TTL);
}
/**