Skip to content

Commit

Permalink
Merge pull request #12 from Symplicity/cancel-job
Browse files Browse the repository at this point in the history
add ability to cancel processing jobs
  • Loading branch information
frets1700 authored Sep 17, 2024
2 parents 8d8240a + 6d03fb3 commit 57f69b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/Resque/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ public function fail($exception)
Resque_Stat::incr('failed:' . $this->worker);
}

public function cancel($exception)
{
Resque_Event::trigger('onCancel', array(
'exception' => $exception,
'job' => $this,
));

$this->updateStatus(Resque_Job_Status::STATUS_CANCELLED, $exception);
Resque_Failure::create(
$this->payload,
$exception,
$this->worker,
$this->queue
);
Resque_Stat::incr('failed');
Resque_Stat::incr('failed:' . $this->worker);
}

/**
* Re-queue the current job.
* @return string
Expand Down
3 changes: 2 additions & 1 deletion lib/Resque/Job/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Resque_Job_Status
const STATUS_RUNNING = 2;
const STATUS_FAILED = 3;
const STATUS_COMPLETE = 4;
const STATUS_CANCELLED = 5;
const STATUS_EXPIRE_SECS = 600;

/**
Expand Down Expand Up @@ -92,7 +93,7 @@ public function update($status, $data, $exception=null)
if(!$this->isTracking()) {
return;
}

$now = time();

$statusPacket = array(
Expand Down

0 comments on commit 57f69b4

Please sign in to comment.