我的Resque工作器类
class WebWorker
@queue = :jobs_queue
def self.perform(id)
//bunch of code here
end
end
我这样从队列中移除一个特定的任务
Resque.dequeue(WebWorker,id)
但我想停止运行工作并重新启动,我该怎么做?
我的Resque工作器类
class WebWorker
@queue = :jobs_queue
def self.perform(id)
//bunch of code here
end
end
我这样从队列中移除一个特定的任务
Resque.dequeue(WebWorker,id)
但我想停止运行工作并重新启动,我该怎么做?
尝试如下使用unregister_worker
:
Resque.workers.each(&:unregister_worker)
这个命令将停止工作并将其设置为失败状态。
http://www.rubydoc.info/gems/resque/Resque/Worker:unregister_worker
如果你想停止一个正在进行的作业,而又不想将其标记为失败作业,你可以使用这个技巧。
class Task
@queue = :queue_name
def self.perform(parameters)
pid = Process.fork do
Task.work parameters
end
#puts "parent, pid #{Process.pid}, waiting on child pid #{pid}"
Process.wait
end
def self.work(parameters)
#Your perform code here
end
end
Resque.workers.each do |worker|
#If condition : "current worker is working and is working on the job that we want to stop and is operating on the queue that we require " and please change this condition as per your requirement
if worker.working? and worker.queues.include?("queue_name") and worker.job["payload"]["args"].first==post_id
victim = %x[pgrep -P #{worker.pid}] #Getting child's PID
victim.strip!
victim = %x[pgrep -P #{victim}] #Getting grandchild's PID of worker
victim.strip!
%x[kill -9 #{victim.to_i}]
end
end