mirror of
https://github.com/idanoo/php-resque
synced 2025-07-01 13:42:22 +00:00
add beforeEnqueue hook that allows the enqueue to be cancelled
This commit is contained in:
parent
c335bc3555
commit
a95c24b32e
5 changed files with 106 additions and 29 deletions
|
@ -201,17 +201,24 @@ class Resque
|
|||
*/
|
||||
public static function enqueue($queue, $class, $args = null, $trackStatus = false)
|
||||
{
|
||||
$result = Resque_Job::create($queue, $class, $args, $trackStatus);
|
||||
if ($result) {
|
||||
Resque_Event::trigger('afterEnqueue', array(
|
||||
'class' => $class,
|
||||
'args' => $args,
|
||||
'queue' => $queue,
|
||||
'id' => $result,
|
||||
));
|
||||
$id = Resque::generateJobId();
|
||||
$hookParams = array(
|
||||
'class' => $class,
|
||||
'args' => $args,
|
||||
'queue' => $queue,
|
||||
'id' => $id,
|
||||
);
|
||||
try {
|
||||
Resque_Event::trigger('beforeEnqueue', $hookParams);
|
||||
}
|
||||
catch(Resque_Job_DontCreate $e) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
return $result;
|
||||
Resque_Job::create($queue, $class, $args, $trackStatus, $id);
|
||||
Resque_Event::trigger('afterEnqueue', $hookParams);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -341,5 +348,15 @@ class Resque
|
|||
$result = self::redis()->del('queue:' . $queue);
|
||||
return ($result == 1) ? $counter : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an identifier to attach to a job for status tracking.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateJobId()
|
||||
{
|
||||
return md5(uniqid('', true));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue