From db05793a3cfd0b92596f17fc1cdf33df805dde3e Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 5 Jan 2023 17:25:04 +0200 Subject: [PATCH] tidy up --- app/workers/sync-out.php | 3 +-- src/Appwrite/Platform/Tasks/EdgeSync.php | 26 +++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/workers/sync-out.php b/app/workers/sync-out.php index 4607e77b38..1a9dfbdc13 100644 --- a/app/workers/sync-out.php +++ b/app/workers/sync-out.php @@ -50,7 +50,7 @@ function call(string $url, string $token, array $data): int . json_encode($keys) . $eol; } $payload .= "--" . $delimiter . "--" . $eol; - var_dump($payload); + $status = 404; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, [ @@ -95,7 +95,6 @@ function handle($dbForConsole, $regions, $data): void $token = $jwt->encode([]); foreach ($regions as $code => $region) { - var_dump($region); $time = DateTime::now(); $status = call($region['domain'] . '/v1/edge/sync', $token, $data); if ($status !== Response::STATUS_CODE_OK) { diff --git a/src/Appwrite/Platform/Tasks/EdgeSync.php b/src/Appwrite/Platform/Tasks/EdgeSync.php index c3ff92fd8a..ce30729960 100644 --- a/src/Appwrite/Platform/Tasks/EdgeSync.php +++ b/src/Appwrite/Platform/Tasks/EdgeSync.php @@ -46,14 +46,14 @@ class EdgeSync extends Action Console::success("[{$time}] New task every {$interval} seconds"); foreach ($regions as $code => $region) { - $count = 0; $chunk = 0; $limit = 500; $sum = $limit; $keys = []; + $found = false; while ($sum === $limit) { $chunk++; - + $count = 0; $results = $dbForConsole->find('syncs', [ Query::equal('region', [App::getEnv('_APP_REGION')]), Query::equal('target', [$code]), @@ -62,6 +62,7 @@ class EdgeSync extends Action $sum = count($results); if ($sum > 0) { + $found = true; foreach ($results as $document) { $key = $document->getAttribute('key'); $keys[] = [ @@ -72,17 +73,18 @@ class EdgeSync extends Action $count++; } } - } - if (!empty($keys)) { - Console::info("[{$time}] Enqueueing keys chunk {$count} to region {$code}"); - $queueForEdgeSyncOut - ->enqueue([ - 'region' => $code, - 'keys' => $keys - ]); - } else { - Console::info("[{$time}] No keys where found for region {$code}."); + if (!empty($keys)) { + Console::info("[{$time}] Enqueueing chunk {$chunk}, {$count} keys to region {$code}"); + $queueForEdgeSyncOut + ->enqueue([ + 'region' => $code, + 'keys' => $keys + ]); + } + } + if (!$found) { + Console::info("[{$time}] No keys where found for region {$code}."); } } }, $interval);