From b7d7f43aefe05b35428bf63cb4a3cbde7b8dee06 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 26 Oct 2022 15:10:24 +0300 Subject: [PATCH] addressing comments --- app/config/services.php | 4 ++-- app/workers/sync-out.php | 31 ++++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/config/services.php b/app/config/services.php index 3783696db8..ac6fa5b9d6 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -189,8 +189,8 @@ return [ 'syncs' => [ 'key' => 'edge', 'name' => 'edge', - 'subtitle' => 'Appwrite\'s cache edges sync Endpoint', - 'description' => 'Cache edges sync Endpoint', + 'subtitle' => 'Appwrite\'s cache edge sync Endpoint', + 'description' => 'Cache edge sync Endpoint', 'controller' => 'api/edge.php', 'sdk' => false, 'docs' => false, diff --git a/app/workers/sync-out.php b/app/workers/sync-out.php index bff16cd17d..b6d34096d2 100644 --- a/app/workers/sync-out.php +++ b/app/workers/sync-out.php @@ -4,6 +4,8 @@ require_once __DIR__ . '/../worker.php'; use Ahc\Jwt\JWT; use Appwrite\Utopia\Response; +use Swoole\Runtime; +use Swoole\Timer; use Utopia\App; use Utopia\Config\Config; use Utopia\Database\Database; @@ -102,6 +104,8 @@ $connection = new Queue\Connection\Redis(fn() => $queue); $adapter = new Queue\Adapter\Swoole($connection, 2, 'syncOut'); $server = new Queue\Server($adapter); + + $server->job() ->inject('message') ->inject('dbForConsole') @@ -130,23 +134,16 @@ $server->job() } $keys[$payload['key']] = null; - if (count($keys) >= MAX_KEY_COUNT || ($counter + SUBMITION_INTERVAL) < time()) { - var_dump([ - 'regions' => array_keys($regions), - 'time_h' => date('m/d/Y H:i:s', $counter), - 'because_time' => ($counter + SUBMITION_INTERVAL) < time(), - 'because_count' => count($keys) >= MAX_KEY_COUNT, - 'count' => count($keys), - 'counter' => $counter + SUBMITION_INTERVAL, - 'time' => time(), - 'keys' => array_keys($keys), - ]); - call($dbForConsole, $regions, array_keys($keys)); - $counter = time(); - $keys = []; - } + +// if (count($keys) >= MAX_KEY_COUNT || ($counter + SUBMITION_INTERVAL) < time()) { +// call($dbForConsole, $regions, array_keys($keys)); +// $counter = time(); +// $keys = []; +// } }); +Runtime::enableCoroutine(SWOOLE_HOOK_ALL); + $server ->error() ->inject('error') @@ -157,6 +154,10 @@ $server $server ->workerStart(function () { + Timer::tick(1000, function () { + var_dump(date('m/d/Y H:i:s', time())); + }); echo "Out region [" . App::getEnv('_APP_REGION', 'nyc1') . "] cache purging worker Started" . PHP_EOL; }) ->start(); +