Skip to content

Commit

Permalink
Taking care of a case where the task could have been popped after
Browse files Browse the repository at this point in the history
hasTasks() > 0.
  • Loading branch information
nicktacular committed May 12, 2014
1 parent e7c27e2 commit f1cd2ed
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/phlask/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,17 @@ public function run()
$this->logger->info('Have ' . $this->tasks->count() . ' tasks to start');

//pop a task, init and run
$taskSpec = $this->tasks->popTask();
$task = Task::factory($taskSpec, $this->id);
$this->runningTasks->attach($task);

try {
$task->run();
$this->logger->info('Started ' . $task->getTaskSpec()->getName() . '(' . $task->getPid() . ')');
} catch (Exception\ExecutionException $e) {
$this->logger->warning($e->getMessage());
$this->runningTasks->detach($task);
if ($taskSpec = $this->tasks->popTask()) {
$task = Task::factory($taskSpec, $this->id);
$this->runningTasks->attach($task);

try {
$task->run();
$this->logger->info('Started ' . $task->getTaskSpec()->getName() . '(' . $task->getPid() . ')');
} catch (Exception\ExecutionException $e) {
$this->logger->warning($e->getMessage());
$this->runningTasks->detach($task);
}
}
}

Expand Down

0 comments on commit f1cd2ed

Please sign in to comment.