Reputation: 12923
If I call the following:
return AdventureJob::dispatch($event->character->refresh(), $event->adventure, $event->levelsAtATime)->delay($timeTillFinished);
This will then create a job thats delayed x minutes. my jobs are all processed through redis, is there a way to then get this specific job or delete this specific job from the queue?
People talk about php artisan commands to then delete all jobs, thats not what I want I want to get some kind of information (Job ID? or queue ID? Redis ID?) about this job to then store in the database so that if the player then cancels the adventure, I can use that to find this job on the queue and delete it, assuming it's not running.
Upvotes: 3
Views: 4775
Reputation: 9586
There is no direct or easy way to do it. The delayed jobs are kept in sorted sets
as to-be-processed time as score
and job payload as the value
.
There are several ways to remove an element from the sorted sets(most of them require some efforts depending on the size of the delayed queue) such as
WITHSCORES
. It will give you the list of jobs with their scores. You can use score to identify to be delayed job. Get the value(serialized payload) then use ZREM
.ZREMRANGEBYSCORE
takes time interval.handle
method. This one requires application layer development. Whenever you push a job to the queue you send an identifier to the job, put same identifier(that you can understand) in Redis too(with EXPIRE
greater than the delayed time). When you want to cancel it, then delete it from the Redis. Inside the handle method check whether the given identifier exists in Redis, if not early return from the code block.Upvotes: 2