This commit is contained in:
shimon
2023-01-05 17:25:04 +02:00
parent 9860b013fb
commit db05793a3c
2 changed files with 15 additions and 14 deletions
+1 -2
View File
@@ -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) {
+14 -12
View File
@@ -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);