Test worker wrapers
This commit is contained in:
parent
b75d33efc1
commit
de17d0d1d3
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Resque\Worker;
|
||||
use Utopia\Audit\Audit;
|
||||
use Utopia\Audit\Adapters\MySQL as AuditAdapter;
|
||||
use Utopia\CLI\Console;
|
||||
|
@ -10,15 +11,15 @@ Console::title('Audits V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' audits worker v1 has started');
|
||||
|
||||
class AuditsV1
|
||||
class AuditsV1 extends Worker
|
||||
{
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -39,7 +40,7 @@ class AuditsV1
|
|||
$audit->log($userId, $event, $resource, $userAgent, $ip, '', $data);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
|||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Network\Validator\CNAME;
|
||||
use Appwrite\Resque\Worker;
|
||||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
|
@ -16,15 +17,15 @@ Console::title('Certificates V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' certificates worker v1 has started');
|
||||
|
||||
class CertificatesV1
|
||||
class CertificatesV1 extends Worker
|
||||
{
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -204,8 +205,7 @@ class CertificatesV1
|
|||
Authorization::reset();
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
|||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Document;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Utopia\Storage\Device\Local;
|
||||
use Utopia\Abuse\Abuse;
|
||||
use Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
@ -19,18 +20,17 @@ Console::title('Deletes V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' deletes worker v1 has started'."\n");
|
||||
|
||||
class DeletesV1
|
||||
class DeletesV1 extends Worker
|
||||
{
|
||||
|
||||
public $args = [];
|
||||
|
||||
protected $consoleDB = null;
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
$projectId = $this->args['projectId'];
|
||||
$type = $this->args['type'];
|
||||
|
@ -82,9 +82,8 @@ class DeletesV1
|
|||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
|
||||
protected function deleteDocuments(Document $document, $projectId)
|
||||
|
|
|
@ -6,6 +6,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
|||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Cron\CronExpression;
|
||||
use Swoole\Runtime;
|
||||
use Utopia\App;
|
||||
|
@ -127,17 +128,17 @@ Console::info(count($list)." functions listed in " . ($executionEnd - $execution
|
|||
|
||||
//TODO aviod scheduled execution if delay is bigger than X offest
|
||||
|
||||
class FunctionsV1
|
||||
class FunctionsV1 extends Worker
|
||||
{
|
||||
public $args = [];
|
||||
|
||||
public $allowed = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -195,7 +196,7 @@ class FunctionsV1
|
|||
|
||||
Console::success('Triggered function: '.$event);
|
||||
|
||||
$this->execute('event', $projectId, '', $database, $function, $event, $payload);
|
||||
$this->run('event', $projectId, '', $database, $function, $event, $payload);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -251,7 +252,7 @@ class FunctionsV1
|
|||
'scheduleOriginal' => $function->getAttribute('schedule', ''),
|
||||
]); // Async task rescheduale
|
||||
|
||||
$this->execute($trigger, $projectId, $executionId, $database, $function);
|
||||
$this->run($trigger, $projectId, $executionId, $database, $function);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -264,7 +265,7 @@ class FunctionsV1
|
|||
throw new Exception('Function not found ('.$functionId.')');
|
||||
}
|
||||
|
||||
$this->execute($trigger, $projectId, $executionId, $database, $function);
|
||||
$this->run($trigger, $projectId, $executionId, $database, $function);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -286,7 +287,7 @@ class FunctionsV1
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = ''): void
|
||||
public function run(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = ''): void
|
||||
{
|
||||
global $list;
|
||||
|
||||
|
@ -548,7 +549,7 @@ class FunctionsV1
|
|||
return $output;
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Resque\Worker;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
|
||||
|
@ -9,18 +10,18 @@ Console::title('Mails V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' mails worker v1 has started'."\n");
|
||||
|
||||
class MailsV1
|
||||
class MailsV1 extends Worker
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -69,8 +70,7 @@ class MailsV1
|
|||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use Appwrite\Database\Database;
|
|||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Resque\Worker;
|
||||
use Cron\CronExpression;
|
||||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
@ -15,18 +16,18 @@ Console::title('Tasks V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' tasks worker v1 has started');
|
||||
|
||||
class TasksV1
|
||||
class TasksV1 extends Worker
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -73,11 +74,11 @@ class TasksV1
|
|||
}
|
||||
|
||||
if ($task->getAttribute('updated') !== $updated) { // Task have already been rescheduled by owner
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($task->getAttribute('status') !== 'play') { // Skip task and don't schedule again
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Reschedule
|
||||
|
@ -202,11 +203,10 @@ class TasksV1
|
|||
|
||||
// Send alert if needed (use SMTP as default for now)
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Appwrite\Resque\Worker;
|
||||
use Utopia\App;
|
||||
use Utopia\CLI\Console;
|
||||
|
||||
|
@ -9,18 +10,18 @@ Console::title('Usage V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' usage worker v1 has started');
|
||||
|
||||
class UsageV1
|
||||
class UsageV1 extends Worker
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -65,8 +66,7 @@ class UsageV1
|
|||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use Appwrite\Database\Database;
|
|||
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
|
||||
use Appwrite\Database\Adapter\Redis as RedisAdapter;
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Resque\Worker;
|
||||
|
||||
require_once __DIR__.'/../init.php';
|
||||
|
||||
|
@ -14,15 +15,15 @@ Console::title('Webhooks V1 Worker');
|
|||
|
||||
Console::success(APP_NAME.' webhooks worker v1 has started');
|
||||
|
||||
class WebhooksV1
|
||||
class WebhooksV1 extends Worker
|
||||
{
|
||||
public $args = [];
|
||||
|
||||
public function setUp(): void
|
||||
public function init(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function perform()
|
||||
public function execute(): void
|
||||
{
|
||||
global $register;
|
||||
|
||||
|
@ -111,8 +112,7 @@ class WebhooksV1
|
|||
}
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
public function shutdown(): void
|
||||
{
|
||||
// ... Remove environment for this job
|
||||
}
|
||||
}
|
||||
|
|
45
src/Appwrite/Resque/Worker.php
Normal file
45
src/Appwrite/Resque/Worker.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Resque;
|
||||
|
||||
use Swoole\Runtime;
|
||||
|
||||
use function Swoole\Coroutine\run;
|
||||
|
||||
abstract class Worker
|
||||
{
|
||||
public $args = [];
|
||||
|
||||
abstract public function init(): void;
|
||||
|
||||
abstract public function execute(): void;
|
||||
|
||||
abstract public function shutdown(): void;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
run(function() {
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
$this->init();
|
||||
});
|
||||
}
|
||||
|
||||
public function perform()
|
||||
{
|
||||
run(function() {
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
$this->execute();
|
||||
});
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
run(function() {
|
||||
Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
|
||||
|
||||
$this->shutdown();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue