private function canRemoveTask(Task $task)
{
if (!$task instanceof Process) {
return true;
}
if ($this->isTaskExpired($task) || $this->isTaskCancelled($task)) {
$this->killTask($task);
return true;
}
$processes = array_filter($this->running, function (Task $task) {
return $task instanceof Process;
});
if (count($processes) < 1) {
return true;
}
$found = false;
$stats = $this->getStatsForProcesses($processes);
foreach ($stats as $stat) {
if ($stat[0] === $task->getId()) {
$found = true;
}
}
return !$found;
}