Skip to content

Commit

Permalink
Force stop on stopping deffered task if it not running after 10 s…
Browse files Browse the repository at this point in the history
…econds #12
  • Loading branch information
imsamurai committed Jul 16, 2014
1 parent ee98e69 commit c2bc9e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Model/TaskClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public function add($command, $path, array $arguments = array(), array $options
* Stop task by id
*
* @param int $taskId Unique task id
* @param int $retry Retry count
* @return boolean True if success
* @throws NotFoundException If no such task found
*/
public function stop($taskId) {
public function stop($taskId, $retry = 0) {
$task = $this->read(null, $taskId);

if (!$task) {
Expand All @@ -108,8 +109,11 @@ public function stop($taskId) {
return $this->saveField('status', TaskType::STOPPING);

case TaskType::DEFFERED: {
if ($retry >= 10) {
return $this->saveField('status', TaskType::STOPPED);
}
sleep(1);
return $this->stop($taskId);
return $this->stop($taskId, ++$retry);
}
default:
return false;
Expand Down

0 comments on commit c2bc9e1

Please sign in to comment.