如何在带有Rails的另一个作业中检查运行作业的sidekiq的类名

问题描述 投票:-1回答:1

如何查找正在运行的sidekiq类的名称?

示例]我的sidekiq计划程序中有两项工作

job1#将每隔1秒运行一次

job2#每5秒就会跑一次蜜蜂

在job2中,如何检查job1是否正在运行?

未运行的作业ID或计数

我必须知道正在运行的类名

ruby-on-rails ruby jobs sidekiq
1个回答
0
投票

您可以使用以下方式找到您的奔跑工人:

workers = Sidekiq::Workers.new
workers.size => 2
workers.each do |process_id, thread_id, work|
  # process_id is a unique identifier per Sidekiq process
  # thread_id is a unique identifier per thread
  # work is a Hash which looks like:
  # { 'queue' => name, 'run_at' => timestamp, 'payload' => msg }
  # run_at is an epoch Integer.
end

输出:

{"queue"=>"default", "payload"=>{"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"CheckAndRequestEmailJob", "queue"=>"default", "args"=>[{"job_class"=>"CheckAndRequestEmailJob", "job_id"=>"f65ef06a-ce3b-4edf-a634-297d74966735", "provider_job_id"=>nil, "queue_name"=>"default", "priority"=>nil, "arguments"=>[], "executions"=>0, "locale"=>"ko"}], "retry"=>true, "jid"=>"4d6979b658f37b120dfd8032", "created_at"=>1575855413.598507, "enqueued_at"=>1575855413.598607}, "run_at"=>1575855413}

如果要查找类名,请使用:

workers = Sidekiq::Workers.new
workers.each do |process_id, thread_id, work|
  puts work['payload']['args'][0]['job_class']
end

和输出:

CheckAndRequestEmailJob
© www.soinside.com 2019 - 2024. All rights reserved.