tidy up
This commit is contained in:
parent
3a651adea5
commit
9d641b985a
2 changed files with 19 additions and 26 deletions
|
@ -471,15 +471,17 @@ App::put('/v1/functions/:functionId')
|
||||||
|
|
||||||
$log = $dbForConsole->getDocument('schedules', $function['scheduleId']);
|
$log = $dbForConsole->getDocument('schedules', $function['scheduleId']);
|
||||||
|
|
||||||
$active = !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'));
|
/**
|
||||||
|
* In case we want to clear the schedule
|
||||||
if ($active) {
|
*/
|
||||||
|
if (!empty($function->getAttribute('deployment'))) {
|
||||||
$log->setAttribute('resourceUpdatedAt', $function['scheduleUpdatedAt']);
|
$log->setAttribute('resourceUpdatedAt', $function['scheduleUpdatedAt']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$log
|
$log
|
||||||
->setAttribute('schedule', $function->getAttribute('schedule'))
|
->setAttribute('schedule', $function->getAttribute('schedule'))
|
||||||
->setAttribute('active', $active);
|
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
|
||||||
|
|
||||||
|
|
||||||
$dbForConsole->updateDocument('schedules', $log->getId(), $log);
|
$dbForConsole->updateDocument('schedules', $log->getId(), $log);
|
||||||
|
|
||||||
|
|
|
@ -52,14 +52,14 @@ $cli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$loadEnd = \microtime(true);
|
$loadEnd = \microtime(true);
|
||||||
Console::error("Queue was built in " . ($loadEnd - $loadStart) . " seconds");
|
Console::success("Queue was built in " . ($loadEnd - $loadStart) . " seconds");
|
||||||
};
|
};
|
||||||
|
|
||||||
$removeFromQueue = function ($scheduleId) use (&$queue) {
|
$removeFromQueue = function ($scheduleId) use (&$queue) {
|
||||||
foreach ($queue as $slot => $schedule) {
|
foreach ($queue as $slot => $schedule) {
|
||||||
foreach ($schedule as $function) {
|
foreach ($schedule as $function) {
|
||||||
if ($scheduleId === $function['resourceId']) {
|
if ($scheduleId === $function['resourceId']) {
|
||||||
Console::info("Unsetting :{$function['resourceId']} from queue slot $slot");
|
Console::error("Unsetting :{$function['resourceId']} from queue slot $slot");
|
||||||
unset($queue[$slot][$function['resourceId']]);
|
unset($queue[$slot][$function['resourceId']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ $cli
|
||||||
foreach ($results as $document) {
|
foreach ($results as $document) {
|
||||||
$functions[$document['resourceId']] = [
|
$functions[$document['resourceId']] = [
|
||||||
'resourceId' => $document->getAttribute('resourceId'),
|
'resourceId' => $document->getAttribute('resourceId'),
|
||||||
'resourceUpdatedAt' => $document->getAttribute('resourceUpdatedAt'),
|
|
||||||
'schedule' => $document->getAttribute('schedule'),
|
'schedule' => $document->getAttribute('schedule'),
|
||||||
|
'resourceUpdatedAt' => $document->getAttribute('resourceUpdatedAt'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +100,7 @@ $cli
|
||||||
}
|
}
|
||||||
|
|
||||||
$loadEnd = \microtime(true);
|
$loadEnd = \microtime(true);
|
||||||
Console::error("{$total} functions where loaded in " . ($loadEnd - $loadStart) . " seconds");
|
Console::success("{$total} functions where loaded in " . ($loadEnd - $loadStart) . " seconds");
|
||||||
|
|
||||||
$createQueue();
|
$createQueue();
|
||||||
$lastUpdate = DateTime::addSeconds(new \DateTime(), -FUNCTION_UPDATE_TIMER);
|
$lastUpdate = DateTime::addSeconds(new \DateTime(), -FUNCTION_UPDATE_TIMER);
|
||||||
|
|
||||||
|
@ -112,13 +111,13 @@ $cli
|
||||||
function () use ($removeFromQueue, $createQueue, $dbForConsole, &$functions, &$queue, &$lastUpdate) {
|
function () use ($removeFromQueue, $createQueue, $dbForConsole, &$functions, &$queue, &$lastUpdate) {
|
||||||
Timer::tick(FUNCTION_UPDATE_TIMER * 1000, function () use ($removeFromQueue, $createQueue, $dbForConsole, &$functions, &$queue, &$lastUpdate) {
|
Timer::tick(FUNCTION_UPDATE_TIMER * 1000, function () use ($removeFromQueue, $createQueue, $dbForConsole, &$functions, &$queue, &$lastUpdate) {
|
||||||
$time = DateTime::now();
|
$time = DateTime::now();
|
||||||
$limit = 200;
|
$limit = 1000;
|
||||||
$sum = $limit;
|
$sum = $limit;
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$latestDocument = null;
|
$latestDocument = null;
|
||||||
$timerStart = \microtime(true);
|
$timerStart = \microtime(true);
|
||||||
|
|
||||||
Console::info("Update proc run at: $time last update was at $lastUpdate");
|
Console::warning("Update proc started at: $time last update was at $lastUpdate");
|
||||||
|
|
||||||
while ($sum === $limit) {
|
while ($sum === $limit) {
|
||||||
$paginationQueries = [Query::limit($limit)];
|
$paginationQueries = [Query::limit($limit)];
|
||||||
|
@ -137,14 +136,14 @@ $cli
|
||||||
$org = isset($functions[$document['resourceId']]) ? strtotime($functions[$document['resourceId']]['resourceUpdatedAt']) : null;
|
$org = isset($functions[$document['resourceId']]) ? strtotime($functions[$document['resourceId']]['resourceUpdatedAt']) : null;
|
||||||
$new = strtotime($document['resourceUpdatedAt']);
|
$new = strtotime($document['resourceUpdatedAt']);
|
||||||
if ($document['active'] === false) {
|
if ($document['active'] === false) {
|
||||||
Console::info("Removing: {$document['resourceId']}");
|
Console::warning("Removing: {$document['resourceId']}");
|
||||||
unset($functions[$document['resourceId']]);
|
unset($functions[$document['resourceId']]);
|
||||||
} elseif ($new > $org) {
|
} elseif ($new > $org) {
|
||||||
Console::info("Updating: {$document['resourceId']}");
|
Console::warning("Updating: {$document['resourceId']}");
|
||||||
$functions[$document['resourceId']] = [
|
$functions[$document['resourceId']] = [
|
||||||
'resourceId' => $document->getAttribute('resourceId'),
|
'resourceId' => $document->getAttribute('resourceId'),
|
||||||
'resourceUpdatedAt' => $document->getAttribute('resourceUpdatedAt'),
|
|
||||||
'schedule' => $document->getAttribute('schedule'),
|
'schedule' => $document->getAttribute('schedule'),
|
||||||
|
'resourceUpdatedAt' => $document->getAttribute('resourceUpdatedAt'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$removeFromQueue($document['resourceId']);
|
$removeFromQueue($document['resourceId']);
|
||||||
|
@ -157,7 +156,7 @@ $cli
|
||||||
$createQueue();
|
$createQueue();
|
||||||
$timerEnd = \microtime(true);
|
$timerEnd = \microtime(true);
|
||||||
|
|
||||||
Console::error("Update timer: {$total} functions where updated in " . ($timerEnd - $timerStart) . " seconds");
|
Console::warning("Update timer: {$total} functions where updated in " . ($timerEnd - $timerStart) . " seconds");
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,18 +168,11 @@ $cli
|
||||||
$timeFrame = DateTime::addSeconds(new \DateTime(), ENQUEUE_TIME_FRAME); /** 5 min */
|
$timeFrame = DateTime::addSeconds(new \DateTime(), ENQUEUE_TIME_FRAME); /** 5 min */
|
||||||
$slot = (new \DateTime())->format('Y-m-d H:i:00.000');
|
$slot = (new \DateTime())->format('Y-m-d H:i:00.000');
|
||||||
|
|
||||||
Console::info("Enqueue proc run at: $time");
|
Console::info("Enqueue proc started at: $time");
|
||||||
// Debug
|
|
||||||
// foreach ($queue as $slot => $schedule) {
|
|
||||||
// Console::log("Slot: $slot");
|
|
||||||
// foreach ($schedule as $function) {
|
|
||||||
// Console::log("{$function['resourceId']} {$function['schedule']}");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (array_key_exists($slot, $queue)) {
|
if (array_key_exists($slot, $queue)) {
|
||||||
$schedule = $queue[$slot];
|
$schedule = $queue[$slot];
|
||||||
console::log("Number of function sent to worker (" . count($schedule));
|
console::info(count($schedule) . " functions sent to worker for time slot " . $slot);
|
||||||
|
|
||||||
foreach ($schedule as $function) {
|
foreach ($schedule as $function) {
|
||||||
/**
|
/**
|
||||||
|
@ -199,7 +191,6 @@ $cli
|
||||||
!empty($functions[$function['resourceId']] &&
|
!empty($functions[$function['resourceId']] &&
|
||||||
$function['schedule'] === $functions[$function['resourceId']]['schedule'])
|
$function['schedule'] === $functions[$function['resourceId']]['schedule'])
|
||||||
) {
|
) {
|
||||||
//Console::warning("re-enqueueing :{$function['resourceId']}");
|
|
||||||
$queue[$next][$function['resourceId']] = $function;
|
$queue[$next][$function['resourceId']] = $function;
|
||||||
}
|
}
|
||||||
unset($queue[$slot][$function['resourceId']]); /** removing function from slot */
|
unset($queue[$slot][$function['resourceId']]); /** removing function from slot */
|
||||||
|
@ -207,7 +198,7 @@ $cli
|
||||||
unset($queue[$slot]); /** removing slot */
|
unset($queue[$slot]); /** removing slot */
|
||||||
}
|
}
|
||||||
$timerEnd = \microtime(true);
|
$timerEnd = \microtime(true);
|
||||||
Console::error("Queue timer: finished in " . ($timerEnd - $timerStart) . " seconds");
|
Console::info("Queue timer: finished in " . ($timerEnd - $timerStart) . " seconds");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue