Skip to content

Commit 32f5c6e

Browse files
committed
implement removedelayed and removedelayedjobfromtimestamp
1 parent c9569ea commit 32f5c6e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

lib/ResqueScheduler.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,60 @@ public static function getDelayedTimestampSize($timestamp)
8888
$timestamp = self::toTimestamp($timestamp);
8989
return Resque::redis()->llen('delayed:' . $timestamp, $timestamp);
9090
}
91+
92+
/**
93+
* Remove a delayed job from the queue
94+
*
95+
* note: you must specify exactly the same
96+
* queue, class and arguments that you used when you added
97+
* to the delayed queue
98+
*
99+
* also, this is an expensive operation because all delayed keys have tobe
100+
* searched
101+
*
102+
* @param $queue
103+
* @param $class
104+
* @param $args
105+
* @return int number of jobs that were removed
106+
*/
107+
public static function removeDelayed($queue, $class, $args)
108+
{
109+
$destroyed=0;
110+
$item=json_encode(self::jobToHash($queue, $class, $args));
111+
$redis=Resque::redis();
112+
113+
foreach($redis->keys('delayed:*') as $key)
114+
{
115+
$key=$redis->removePrefix($key);
116+
$destroyed+=$redis->lrem($key,0,$item);
117+
}
118+
119+
return $destroyed;
120+
}
121+
122+
/**
123+
* removed a delayed job queued for a specific timestamp
124+
*
125+
* note: you must specify exactly the same
126+
* queue, class and arguments that you used when you added
127+
* to the delayed queue
128+
*
129+
* @param $timestamp
130+
* @param $queue
131+
* @param $class
132+
* @param $args
133+
* @return mixed
134+
*/
135+
public static function removeDelayedJobFromTimestamp($timestamp, $queue, $class, $args)
136+
{
137+
$key = 'delayed:' . self::getTimestamp($timestamp);
138+
$item = json_encode(self::jobToHash($queue, $class, $args));
139+
$redis = Resque::redis();
140+
$count = $redis->lrem($key, 0, $item);
141+
self::cleanupTimestamp($key, $timestamp);
142+
143+
return $count;
144+
}
91145

92146
/**
93147
* Generate hash of all job properties to be saved in the scheduled queue.

0 commit comments

Comments
 (0)