diff --git a/app/config/collections.php b/app/config/collections.php index 5cfb09633a..d148e31b9d 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -52,17 +52,6 @@ $collections = [ 'array' => false, 'filters' => ['json'], ], - [ - '$id' => ID::custom('requestedAt'), - 'type' => Database::VAR_DATETIME, - 'format' => '', - 'size' => 0, - 'signed' => false, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => ['datetime'], - ], [ '$id' => ID::custom('status'), 'type' => Database::VAR_INTEGER, @@ -75,9 +64,9 @@ $collections = [ ], 'indexes' => [ [ - '$id' => ID::custom('_key_requestedAt_status'), + '$id' => ID::custom('_key_status'), 'type' => Database::INDEX_KEY, - 'attributes' => ['requestedAt', 'status'], + 'attributes' => ['status'], 'lengths' => [], 'orders' => [], ], diff --git a/app/init.php b/app/init.php index 470552fc74..6cf3ef3953 100644 --- a/app/init.php +++ b/app/init.php @@ -929,10 +929,6 @@ App::setResource('console', function () { ]); }, []); -$register->set('syncOut', function () { - return new SyncOut(); -}); - $register->set('workerRedisConnection', function () { return new redisQueue('redis', 6379); }); @@ -982,21 +978,34 @@ App::setResource('dbForProject', function ($db, $cache, Document $project, $regi }, ['db', 'cache', 'project', 'register']); App::setResource('dbForConsole', function ($db, $cache, $register) { - $cache = new Cache(new RedisCache($cache)); - $cache->on(cache::EVENT_SAVE, function ($key) use ($register) { + $register - ->get('syncOut') - ->addKey($key) - ->trigger(); + ->get('workerSyncOut') + ->resetStats(); + $register + ->get('workerSyncOut') + ->enqueue([ + 'type' => 'saved from init', + 'value' => [ + 'key' => $key + ] + ]); }); $cache->on(cache::EVENT_PURGE, function ($key) use ($register) { $register - ->get('syncOut') - ->addKey($key) - ->trigger(); + ->get('workerSyncOut') + ->resetStats(); + $register + ->get('workerSyncOut') + ->enqueue([ + 'type' => 'purge from init', + 'value' => [ + 'key' => $key + ] + ]); }); $database = new Database(new MariaDB($db), $cache); diff --git a/app/workers/syncsOut.php b/app/workers/syncsOut.php index b0029a10dd..000af2bf5c 100644 --- a/app/workers/syncsOut.php +++ b/app/workers/syncsOut.php @@ -132,9 +132,9 @@ function call($regions, $keys): void foreach ($regions as $code => $region) { $status = send($region['domain'] . '/v1/edge', $token, ['keys' => $keys]); + var_dump('Sending request...............'); if ($status !== Response::STATUS_CODE_OK) { getDB(DATABASE_CONSOLE)->createDocument('syncs', new Document([ - 'requestedAt' => DateTime::now(), 'regionOrg' => CURRENT_REGION, 'regionDest' => $code, 'keys' => $keys, @@ -170,12 +170,24 @@ $server->job() if (!empty($payload['chunk'])) { + var_dump('from chunk'); call($regions, $payload['chunk']); return; } $keys[$payload['key']] = null; if (count($keys) >= MAX_KEY_COUNT || ($counter + SUBMITION_INTERVAL) < time()) { + var_dump('from key'); + var_dump([ + 'regions' => array_keys($regions), + 'because_time' => ($counter + SUBMITION_INTERVAL) < time(), + 'because_count' => count($keys) >= MAX_KEY_COUNT, + 'count' => count($keys), + 'counter' => $counter + SUBMITION_INTERVAL, + 'time' => time(), + + + ]); call($regions, array_keys($keys)); $counter = time(); $keys = [];