Locating and removing a delayed resque job

梦想与她 提交于 2019-12-10 11:56:16

问题


I have a resque job that got caught up in some bad code and is infinitely getting reque'd after failing over repeatedly. I'd like to remove the job manually, somehow, but I'm not sure what the name of the job is in the redis namespace. It isn't in 'failed' because I'm catching the actual exception. In the exception, I add the job back to the resque queue using Resque.enqueue_in(). How do I figure out what the name of the job is in redis so I can delete the key/job from ever happening?


回答1:


Resque poll a redis list that essentially a queue if you want to remove a message from the redis then you can try this

require "rubygems"
require "redis"
require 'redis/namespace'
redis = Redis.new
namespace ||= :resque

@redis = Redis::Namespace.new(namespace, :redis => redis)
## If you dont know how does the job payload look like then find inside the list
## normally the payload look like this 
## {'class' => 'ProcessCSV' , args => ['1'] }.to_json.inpsect 
list_job_payloads = @redis.lrange "queue:[my queue name]",0,-1

## then finally remove from the list
@redis.lrem "queue:[my_queue_name]",0,value

But I guess more better approach would be to delete the job via resque like this

Considering that the below is the job payload push to your redis list by resque

 { 'class' => 'ProcessCSV', 'args' => ['1'] }

Then you can delete the payload using

 Resque::Job.destroy(queue, 'ProcessCSV', '1')

It also describe in more detail over here



来源:https://stackoverflow.com/questions/13805796/locating-and-removing-a-delayed-resque-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!