Skip to content

Commit

Permalink
Add helper methods to track working jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Apr 25, 2016
1 parent 1eb242a commit 8fc5efb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ public static function size($queue)
return self::redis()->llen('queue:' . $queue);
}

/**
* Return the size (number of working jobs) of the specified queue.
*
* @param string $queue name of the queue to be checked for working jobs
*
* @return int The size of the working queue.
*/
public static function sizeWorking($queue) {
return Resque::redis()->llen('working:' . $queue);
}

/**
* Create a new job and save it to the specified queue.
*
Expand Down
9 changes: 6 additions & 3 deletions lib/Resque/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function perform()
{
try {
Resque_Event::trigger('beforePerform', $this);
Resque::redis()->lpush('working:' . $this->queue, $this->payload['id']);

$instance = $this->getInstance();
if(method_exists($instance, 'setUp')) {
Expand All @@ -205,6 +206,7 @@ public function perform()
$instance->tearDown();
}

Resque::redis()->lrem('working:' . $this->queue, 0, $this->payload['id']);
Resque_Event::trigger('afterPerform', $this);
}
// beforePerform/setUp have said don't perform this job. Return.
Expand All @@ -220,8 +222,8 @@ public function perform()
*
* @param $exception
*/
public function fail($exception)
{
public function fail($exception) {
Resque::redis()->lrem('working:' . $this->queue, 0, $this->payload['id']);
Resque_Event::trigger('onFailure', array(
'exception' => $exception,
'job' => $this,
Expand Down Expand Up @@ -250,7 +252,8 @@ public function recreate()
$monitor = true;
$status->update(Resque_Job_Status::STATUS_WAITING);
}


Resque::redis()->lrem('working:' . $this->queue, 0, $this->payload['id']);
Resque_Event::trigger('onRecreate', array(
'job' => $this,
));
Expand Down

0 comments on commit 8fc5efb

Please sign in to comment.