Changed SuperVisor to support halting on Constrained tasks. Good default setting.
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:
Abel Hoogeveen 2020-07-17 15:12:02 +02:00
parent be3d5d56e8
commit fcda6d6e4d
2 changed files with 17 additions and 12 deletions

View File

@ -109,12 +109,17 @@ try {
// And finally, run the supervisor // And finally, run the supervisor
try { try {
$supervisor = $lib->getSuperVisor($bootstrap); $supervisor = $lib->getSuperVisor($bootstrap);
while ($supervisor->cycle() !== SuperVisor::FINISHED) { $res = SuperVisor::RUNNING;
while ($res === SuperVisor::RUNNING) {
$res = $supervisor->cycle();
usleep(250000); usleep(250000);
} }
// Write results // 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) { } catch (InvalidArgumentException | TasksException | LibraryException $e) {
fwrite(STDERR, sprintf('FuzeWorks Async could not load.' . PHP_EOL . fwrite(STDERR, sprintf('FuzeWorks Async could not load.' . PHP_EOL .
'Exception: ' . $e->getMessage() . PHP_EOL) 'Exception: ' . $e->getMessage() . PHP_EOL)

View File

@ -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 the task changed status, task is no longer pending and should be processed by another statement
if ($task->getStatus() !== Task::PENDING) 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; continue;
} }
@ -101,7 +101,7 @@ class ParallelSuperVisor implements SuperVisor
// Modify the task in TaskStorage // Modify the task in TaskStorage
$this->taskStorage->modifyTask($task); $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 // 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); $task->setStatus(Task::PENDING);
$this->taskStorage->modifyTask($task); $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 // 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 // If any changes have been made, they should be written to TaskStorage
$task->endTaskTime(); $task->endTaskTime();
$this->taskStorage->modifyTask($task); $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 // 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->setStatus(Task::RUNNING);
$task->startTaskTime(); $task->startTaskTime();
$this->taskStorage->modifyTask($task); $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; continue;
} }
} }
@ -183,7 +183,7 @@ class ParallelSuperVisor implements SuperVisor
$task->setStatus(Task::CANCELLED); $task->setStatus(Task::CANCELLED);
$this->taskStorage->modifyTask($task); $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 // SUCCESS: if a task has succeeded, see if it needs a postHandler
@ -200,7 +200,7 @@ class ParallelSuperVisor implements SuperVisor
$task->setStatus(Task::COMPLETED); $task->setStatus(Task::COMPLETED);
$this->taskStorage->modifyTask($task); $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 // 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 // If any changes have been made, they should be written to TaskStorage
$task->endPostTime(); $task->endPostTime();
$this->taskStorage->modifyTask($task); $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) if ($task->getStatus() !== Task::COMPLETED && $task->getStatus() !== Task::CANCELLED)
$allCompleted = false; $allCompleted = false;
elseif ($task->getStatus() === Task::DELAYED) if ($task->getStatus() === Task::DELAYED)
$anyDelayed = true; $anyDelayed = true;
} }
// If all are finished and none are delayed // If all are finished and none are delayed
if ($allCompleted && !$anyDelayed) if ($allCompleted && !$anyDelayed)
return SuperVisor::FINISHED; return SuperVisor::FINISHED;
if ($allCompleted && $anyDelayed) if (!$allCompleted && $anyDelayed)
return SuperVisor::CONSTRAINED; return SuperVisor::CONSTRAINED;
else else
return SuperVisor::RUNNING; return SuperVisor::RUNNING;