Changed SuperVisor to support halting on Constrained tasks. Good default setting.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Also changed some logging to have PHP_EOL at the end and not at the beginning of the string.
This commit is contained in:
parent
be3d5d56e8
commit
fcda6d6e4d
@ -109,12 +109,17 @@ try {
|
||||
// And finally, run the supervisor
|
||||
try {
|
||||
$supervisor = $lib->getSuperVisor($bootstrap);
|
||||
while ($supervisor->cycle() !== SuperVisor::FINISHED) {
|
||||
$res = SuperVisor::RUNNING;
|
||||
while ($res === SuperVisor::RUNNING) {
|
||||
$res = $supervisor->cycle();
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
// Write results
|
||||
fwrite(STDOUT, "SuperVisor finished scheduled tasks.");
|
||||
if ($res === SuperVisor::CONSTRAINED)
|
||||
fwrite(STDOUT, "SuperVisor finished due to constrained tasks." . PHP_EOL);
|
||||
else
|
||||
fwrite(STDOUT, "SuperVisor finished due to finishing all tasks." . PHP_EOL);
|
||||
} catch (InvalidArgumentException | TasksException | LibraryException $e) {
|
||||
fwrite(STDERR, sprintf('FuzeWorks Async could not load.' . PHP_EOL .
|
||||
'Exception: ' . $e->getMessage() . PHP_EOL)
|
||||
|
@ -90,7 +90,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
// If the task changed status, task is no longer pending and should be processed by another statement
|
||||
if ($task->getStatus() !== Task::PENDING)
|
||||
{
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
|
||||
// Modify the task in TaskStorage
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
// DELAYED: If task is delayed, and enough time has passed, change the status back to pending
|
||||
@ -110,7 +110,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
{
|
||||
$task->setStatus(Task::PENDING);
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
// RUNNING: check if task is still running. If not, set result based on output
|
||||
@ -142,7 +142,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
// If any changes have been made, they should be written to TaskStorage
|
||||
$task->endTaskTime();
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
// FAILED: if a process has failed, attempt to rety if requested to do so
|
||||
@ -166,7 +166,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
$task->setStatus(Task::RUNNING);
|
||||
$task->startTaskTime();
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
$task->setStatus(Task::CANCELLED);
|
||||
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
// SUCCESS: if a task has succeeded, see if it needs a postHandler
|
||||
@ -200,7 +200,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
$task->setStatus(Task::COMPLETED);
|
||||
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
// POST: when a task is currently running in it's postHandler
|
||||
@ -242,7 +242,7 @@ class ParallelSuperVisor implements SuperVisor
|
||||
// If any changes have been made, they should be written to TaskStorage
|
||||
$task->endPostTime();
|
||||
$this->taskStorage->modifyTask($task);
|
||||
fwrite(STDOUT, "\nChanged status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()));
|
||||
fwrite(STDOUT, "Changed status of task '".$task->getId()."' to status " . Task::getStatusType($task->getStatus()) . PHP_EOL);
|
||||
}
|
||||
|
||||
}
|
||||
@ -254,14 +254,14 @@ class ParallelSuperVisor implements SuperVisor
|
||||
{
|
||||
if ($task->getStatus() !== Task::COMPLETED && $task->getStatus() !== Task::CANCELLED)
|
||||
$allCompleted = false;
|
||||
elseif ($task->getStatus() === Task::DELAYED)
|
||||
if ($task->getStatus() === Task::DELAYED)
|
||||
$anyDelayed = true;
|
||||
}
|
||||
|
||||
// If all are finished and none are delayed
|
||||
if ($allCompleted && !$anyDelayed)
|
||||
return SuperVisor::FINISHED;
|
||||
if ($allCompleted && $anyDelayed)
|
||||
if (!$allCompleted && $anyDelayed)
|
||||
return SuperVisor::CONSTRAINED;
|
||||
else
|
||||
return SuperVisor::RUNNING;
|
||||
|
Loading…
Reference in New Issue
Block a user