Skip to content

Commit

Permalink
Add queue management commands
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Jan 26, 2024
1 parent 2b31c76 commit 216a5d7
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ RUN chmod +x /usr/local/bin/doctor && \
chmod +x /usr/local/bin/test && \
chmod +x /usr/local/bin/vars && \
chmod +x /usr/local/bin/queue-retry && \
chmod +x /usr/local/bin/queue-count-failed && \
chmod +x /usr/local/bin/queue-count-processing && \
chmod +x /usr/local/bin/queue-count-success && \
chmod +x /usr/local/bin/worker-audits && \
chmod +x /usr/local/bin/worker-certificates && \
chmod +x /usr/local/bin/worker-databases && \
Expand Down
3 changes: 3 additions & 0 deletions bin/queue-count-failed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

php /usr/src/code/app/cli.php queue-count-failed $@
3 changes: 3 additions & 0 deletions bin/queue-count-processing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

php /usr/src/code/app/cli.php queue-count-processing $@
3 changes: 3 additions & 0 deletions bin/queue-count-success
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

php /usr/src/code/app/cli.php queue-count-success $@
57 changes: 57 additions & 0 deletions src/Appwrite/Platform/Tasks/QueueCountFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Appwrite\Platform\Tasks;

use Appwrite\Event\Event;
use Utopia\CLI\Console;
use Utopia\Platform\Action;
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
use Utopia\Validator\WhiteList;

class QueueCountFailed extends Action
{
public static function getName(): string
{
return 'queue-count-failed';
}


public function __construct()
{
$this
->desc('Return the number of failed jobs from a specific queue identified by the name parameter')
->param('name', '', new WhiteList([
Event::DATABASE_QUEUE_NAME,
Event::DELETE_QUEUE_NAME,
Event::AUDITS_QUEUE_NAME,
Event::MAILS_QUEUE_NAME,
Event::FUNCTIONS_QUEUE_NAME,
Event::USAGE_QUEUE_NAME,
Event::WEBHOOK_CLASS_NAME,
Event::CERTIFICATES_QUEUE_NAME,
Event::BUILDS_QUEUE_NAME,
Event::MESSAGING_QUEUE_NAME,
Event::MIGRATIONS_QUEUE_NAME,
Event::HAMSTER_CLASS_NAME
]), 'Queue name')
->inject('queue')
->callback(fn ($name, $queue) => $this->action($name, $queue));
}

/**
* @param string $name The name of the queue to count the failed jobs from
* @param Connection $queue
*/
public function action(string $name, Connection $queue): void
{
if (!$name) {
Console::error('Missing required parameter $name');
return;
}

$queueClient = new Client($name, $queue);

Console::log("Queue: '".$name."' Currently has " . $queueClient->countFailedJobs() . " failed jobs.");
}
}
57 changes: 57 additions & 0 deletions src/Appwrite/Platform/Tasks/QueueCountProcessing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Appwrite\Platform\Tasks;

use Appwrite\Event\Event;
use Utopia\CLI\Console;
use Utopia\Platform\Action;
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
use Utopia\Validator\WhiteList;

class QueueCountProcessing extends Action
{
public static function getName(): string
{
return 'queue-count-processing';
}


public function __construct()
{
$this
->desc('Return the number of currently processing jobs from a specific queue identified by the name parameter')
->param('name', '', new WhiteList([
Event::DATABASE_QUEUE_NAME,
Event::DELETE_QUEUE_NAME,
Event::AUDITS_QUEUE_NAME,
Event::MAILS_QUEUE_NAME,
Event::FUNCTIONS_QUEUE_NAME,
Event::USAGE_QUEUE_NAME,
Event::WEBHOOK_CLASS_NAME,
Event::CERTIFICATES_QUEUE_NAME,
Event::BUILDS_QUEUE_NAME,
Event::MESSAGING_QUEUE_NAME,
Event::MIGRATIONS_QUEUE_NAME,
Event::HAMSTER_CLASS_NAME
]), 'Queue name')
->inject('queue')
->callback(fn ($name, $queue) => $this->action($name, $queue));
}

/**
* @param string $name The name of the queue to count the processing jobs from
* @param Connection $queue
*/
public function action(string $name, Connection $queue): void
{
if (!$name) {
Console::error('Missing required parameter $name');
return;
}

$queueClient = new Client($name, $queue);

Console::log("Queue: '".$name."' Currently has " . $queueClient->countProcessingJobs() . " processing jobs.");
}
}
57 changes: 57 additions & 0 deletions src/Appwrite/Platform/Tasks/QueueCountSuccess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Appwrite\Platform\Tasks;

use Appwrite\Event\Event;
use Utopia\CLI\Console;
use Utopia\Platform\Action;
use Utopia\Queue\Client;
use Utopia\Queue\Connection;
use Utopia\Validator\WhiteList;

class QueueCountSuccess extends Action
{
public static function getName(): string
{
return 'queue-count-success';
}


public function __construct()
{
$this
->desc('Return the number of successful jobs from a specific queue identified by the name parameter')
->param('name', '', new WhiteList([
Event::DATABASE_QUEUE_NAME,
Event::DELETE_QUEUE_NAME,
Event::AUDITS_QUEUE_NAME,
Event::MAILS_QUEUE_NAME,
Event::FUNCTIONS_QUEUE_NAME,
Event::USAGE_QUEUE_NAME,
Event::WEBHOOK_CLASS_NAME,
Event::CERTIFICATES_QUEUE_NAME,
Event::BUILDS_QUEUE_NAME,
Event::MESSAGING_QUEUE_NAME,
Event::MIGRATIONS_QUEUE_NAME,
Event::HAMSTER_CLASS_NAME
]), 'Queue name')
->inject('queue')
->callback(fn ($name, $queue) => $this->action($name, $queue));
}

/**
* @param string $name The name of the queue to count the successful jobs from
* @param Connection $queue
*/
public function action(string $name, Connection $queue): void
{
if (!$name) {
Console::error('Missing required parameter $name');
return;
}

$queueClient = new Client($name, $queue);

Console::log("Queue: '".$name."' Currently has " . $queueClient->countSuccessfulJobs() . " success jobs.");
}
}

0 comments on commit 216a5d7

Please sign in to comment.