Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
CLI::setResource('publisherDatabases', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
CLI::setResource('publisherFunctions', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
CLI::setResource('publisherMigrations', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,12 @@
contentType: ContentType::JSON
))
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
->inject('publisher')
->inject('publisherFunctions')
->inject('response')
->action(function (int|string $threshold, Publisher $publisher, Response $response) {
->action(function (int|string $threshold, Publisher $publisherFunctions, Response $response) {
$threshold = \intval($threshold);

$size = $publisher->getQueueSize(new Queue(Event::FUNCTIONS_QUEUE_NAME));
$size = $publisherFunctions->getQueueSize(new Queue(Event::FUNCTIONS_QUEUE_NAME));

if ($size >= $threshold) {
throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}.");
Expand Down
6 changes: 6 additions & 0 deletions app/init/resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
App::setResource('publisherDatabases', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
App::setResource('publisherFunctions', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
App::setResource('publisherMigrations', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
Expand All @@ -95,6 +98,9 @@
App::setResource('consumerDatabases', function (BrokerPool $consumer) {
return $consumer;
}, ['consumer']);
App::setResource('consumerFunctions', function (BrokerPool $consumer) {
return $consumer;
}, ['consumer']);
App::setResource('consumerMigrations', function (BrokerPool $consumer) {
return $consumer;
}, ['publisher']);
Expand Down
8 changes: 8 additions & 0 deletions app/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@
return $publisher;
}, ['publisher']);

Server::setResource('publisherFunctions', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);

Server::setResource('publisherMigrations', function (BrokerPool $publisher) {
return $publisher;
}, ['publisher']);
Expand All @@ -267,6 +271,10 @@
return $consumer;
}, ['consumer']);

Server::setResource('consumerFunctions', function (BrokerPool $consumer) {
return $consumer;
}, ['consumer']);

Server::setResource('consumerMigrations', function (BrokerPool $consumer) {
return $consumer;
}, ['consumer']);
Expand Down
5 changes: 4 additions & 1 deletion src/Appwrite/Platform/Tasks/ScheduleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ abstract class ScheduleBase extends Action

protected BrokerPool $publisher;
protected BrokerPool $publisherMigrations;
protected BrokerPool $publisherFunctions;

private ?Histogram $collectSchedulesTelemetryDuration = null;
private ?Gauge $collectSchedulesTelemetryCount = null;
Expand All @@ -45,6 +46,7 @@ public function __construct()
->desc("Execute {$type}s scheduled in Appwrite")
->inject('publisher')
->inject('publisherMigrations')
->inject('publisherFunctions')
->inject('dbForPlatform')
->inject('getProjectDB')
->inject('telemetry')
Expand All @@ -67,13 +69,14 @@ protected function updateProjectAccess(Document $project, Database $dbForPlatfor
* 2. Create timer that sync all changes from 'schedules' collection to local copy. Only reading changes thanks to 'resourceUpdatedAt' attribute
* 3. Create timer that prepares coroutines for soon-to-execute schedules. When it's ready, coroutine sleeps until exact time before sending request to worker.
*/
public function action(BrokerPool $publisher, BrokerPool $publisherMigrations, Database $dbForPlatform, callable $getProjectDB, Telemetry $telemetry): void
public function action(BrokerPool $publisher, BrokerPool $publisherMigrations, BrokerPool $publisherFunctions, Database $dbForPlatform, callable $getProjectDB, Telemetry $telemetry): void
{
Console::title(\ucfirst(static::getSupportedResource()) . ' scheduler V1');
Console::success(APP_NAME . ' ' . \ucfirst(static::getSupportedResource()) . ' scheduler v1 has started');

$this->publisher = $publisher;
$this->publisherMigrations = $publisherMigrations;
$this->publisherFunctions = $publisherFunctions;

$this->scheduleTelemetryCount = $telemetry->createGauge('task.schedule.count');
$this->collectSchedulesTelemetryDuration = $telemetry->createHistogram('task.schedule.collect_schedules.duration', 's');
Expand Down
2 changes: 1 addition & 1 deletion src/Appwrite/Platform/Tasks/ScheduleExecutions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function enqueueResources(Database $dbForPlatform, callable $getProjec
{
$intervalEnd = (new \DateTime())->modify('+' . self::ENQUEUE_TIMER . ' seconds');

$queueForFunctions = new Func($this->publisher);
$queueForFunctions = new Func($this->publisherFunctions);

foreach ($this->schedules as $schedule) {
if (!$schedule['active']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Appwrite/Platform/Tasks/ScheduleFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function enqueueResources(Database $dbForPlatform, callable $getProjec

$this->updateProjectAccess($schedule['project'], $dbForPlatform);

$queueForFunctions = new Func($this->publisher);
$queueForFunctions = new Func($this->publisherFunctions);

$queueForFunctions
->setType('schedule')
Expand Down