Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix while enqueuing #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public static function size($queue)
*
* @return string
*/
public static function enqueue($queue, $class, $args = null, $trackStatus = false)
public static function enqueue($queue, $class, $args = null, $trackStatus = false, $prefix = "")
{
$result = Resque_Job::create($queue, $class, $args, $trackStatus);
$result = Resque_Job::create($queue, $class, $args, $trackStatus, $prefix);
if ($result) {
Resque_Event::trigger('afterEnqueue', array(
'class' => $class,
Expand Down
12 changes: 7 additions & 5 deletions lib/Resque/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public function __construct($queue, $payload)
* @param string $class The name of the class that contains the code to execute the job.
* @param array $args Any optional arguments that should be passed when the job is executed.
* @param boolean $monitor Set to true to be able to monitor the status of a job.
* @param string $prefix The prefix needs to be set for the status key
*
* @return string
*/
public static function create($queue, $class, $args = null, $monitor = false)
public static function create($queue, $class, $args = null, $monitor = false, $prefix = "")
{
if($args !== null && !is_array($args)) {
throw new InvalidArgumentException(
Expand All @@ -62,10 +63,11 @@ public static function create($queue, $class, $args = null, $monitor = false)
'class' => $class,
'args' => array($args),
'id' => $id,
'prefix' => $prefix
));

if($monitor) {
Resque_Job_Status::create($id);
Resque_Job_Status::create($id, $prefix);
}

return $id;
Expand Down Expand Up @@ -118,7 +120,7 @@ public function updateStatus($status)
return;
}

$statusInstance = new Resque_Job_Status($this->payload['id']);
$statusInstance = new Resque_Job_Status($this->payload['id'], $this->payload['prefix']);
$statusInstance->update($status);
}

Expand All @@ -129,7 +131,7 @@ public function updateStatus($status)
*/
public function getStatus()
{
$status = new Resque_Job_Status($this->payload['id']);
$status = new Resque_Job_Status($this->payload['id'], $this->payload['prefix']);
return $status->get();
}

Expand Down Expand Up @@ -239,7 +241,7 @@ public function fail($exception)
*/
public function recreate()
{
$status = new Resque_Job_Status($this->payload['id']);
$status = new Resque_Job_Status($this->payload['id'], $this->payload['prefix']);
$monitor = false;
if($status->isTracking()) {
$monitor = true;
Expand Down
14 changes: 10 additions & 4 deletions lib/Resque/Job/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Resque_Job_Status
const STATUS_FAILED = 3;
const STATUS_COMPLETE = 4;

/**
* @var string The prefix of the job status id.
*/
private $prefix;

/**
* @var string The ID of the job this status class refers back to.
*/
Expand All @@ -37,9 +42,10 @@ class Resque_Job_Status
*
* @param string $id The ID of the job to manage the status for.
*/
public function __construct($id)
public function __construct($id, $prefix = "")
{
$this->id = $id;
$this->prefix = $prefix;
}

/**
Expand All @@ -48,14 +54,14 @@ public function __construct($id)
*
* @param string $id The ID of the job to monitor the status of.
*/
public static function create($id)
public static function create($id, $prefix = "")
{
$statusPacket = array(
'status' => self::STATUS_WAITING,
'updated' => time(),
'started' => time(),
);
Resque::redis()->set('job:' . $id . ':status', json_encode($statusPacket));
Resque::redis()->set('job:' . $prefix . $id . ':status', json_encode($statusPacket));
}

/**
Expand Down Expand Up @@ -137,7 +143,7 @@ public function stop()
*/
public function __toString()
{
return 'job:' . $this->id . ':status';
return 'job:' . $this->prefix . $this->id . ':status';
}
}
?>