Implemented other changes requested by Wettennet.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
4758f4154b
commit
be3d5d56e8
@ -109,7 +109,7 @@ try {
|
||||
// And finally, run the supervisor
|
||||
try {
|
||||
$supervisor = $lib->getSuperVisor($bootstrap);
|
||||
while ($supervisor->cycle() !== SuperVisor::RUNNING) {
|
||||
while ($supervisor->cycle() !== SuperVisor::FINISHED) {
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,11 @@ class GroupConstraint implements Constraint
|
||||
$this->maxConcurrent = $maxConcurrent;
|
||||
}
|
||||
|
||||
public function init(Task $task)
|
||||
{
|
||||
$task->addAttribute('groupName', $this->groupName);
|
||||
}
|
||||
|
||||
public function getGroupName(): string
|
||||
{
|
||||
return $this->groupName;
|
||||
|
@ -37,7 +37,12 @@
|
||||
namespace FuzeWorks\Async\Constraint;
|
||||
use FuzeWorks\Async\Constraint;
|
||||
use FuzeWorks\Async\Task;
|
||||
use FuzeWorks\Async\Tasks;
|
||||
use FuzeWorks\Async\TasksException;
|
||||
use FuzeWorks\Exception\FactoryException;
|
||||
use FuzeWorks\Exception\LibraryException;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Libraries;
|
||||
|
||||
class GroupDependencyConstraint implements Constraint
|
||||
{
|
||||
@ -60,8 +65,6 @@ class GroupDependencyConstraint implements Constraint
|
||||
public function intervene(Task $task, array $tasks): bool
|
||||
{
|
||||
// Find whether any task is not completed
|
||||
$hasFailed = false;
|
||||
$hasUnresolved = false;
|
||||
foreach ($tasks as $t)
|
||||
{
|
||||
foreach ($t->getConstraints() as $constraint)
|
||||
@ -69,33 +72,24 @@ class GroupDependencyConstraint implements Constraint
|
||||
// Check whether the constraint is a GroupConstraint
|
||||
if ($constraint instanceof GroupConstraint && $this->groupName === $constraint->getGroupName())
|
||||
{
|
||||
// Check whether GroupConstraint has failed
|
||||
if ($t->getStatus() === Task::CANCELLED)
|
||||
$hasFailed = true;
|
||||
// If the task is not cancelled and not completed, there are unresolved tasks
|
||||
elseif ($t->getStatus() !== Task::COMPLETED)
|
||||
$hasUnresolved = true;
|
||||
$this->returnStatus = Task::DELAYED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are failed tasks, cancel this dependent
|
||||
if ($hasFailed)
|
||||
// After all known tasks have run, check if all have ended without a CANCELLED status
|
||||
$taskStorage = $this->loadTasksLib()->getTaskStorage();
|
||||
$tasks = $taskStorage->getTasksByAttribute('groupName', $this->groupName);
|
||||
foreach ($tasks as $t)
|
||||
{
|
||||
if ($t->getStatus() === Task::CANCELLED)
|
||||
{
|
||||
$this->returnStatus = Task::CANCELLED;
|
||||
$task->setOutput('', 'Task cancelled due to failed group dependency.');
|
||||
return true;
|
||||
}
|
||||
elseif ($hasUnresolved)
|
||||
{
|
||||
$this->returnStatus = Task::DELAYED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the taskList
|
||||
//$task->setOutput(serialize($tasks), '');
|
||||
//$this->returnStatus = Task::CANCELLED;
|
||||
//return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -115,4 +109,25 @@ class GroupDependencyConstraint implements Constraint
|
||||
{
|
||||
return time() + 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the tasks library, so that dependencies can get scanned later
|
||||
*
|
||||
* @return Tasks
|
||||
* @throws TasksException
|
||||
*/
|
||||
private function loadTasksLib(): Tasks
|
||||
{
|
||||
try {
|
||||
/** @var Libraries $libraries */
|
||||
$libraries = Factory::getInstance('libraries');
|
||||
|
||||
/** @var Tasks $tasks */
|
||||
$tasks = $libraries->get('async');
|
||||
|
||||
return $tasks;
|
||||
} catch (FactoryException | LibraryException $e) {
|
||||
throw new TasksException("Could not constrain task. Async library could not be loaded.");
|
||||
}
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ interface TaskStorage
|
||||
*
|
||||
* @param string $attributeKey
|
||||
* @param string $attributeValue
|
||||
* @return array
|
||||
* @return Task[]
|
||||
*/
|
||||
public function getTasksByAttribute(string $attributeKey, string $attributeValue): array;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user