简体   繁体   English

我可以运行rake任务来模拟sidekiq运行吗?

[英]Can I run a rake task to simulate sidekiq running?

I have a rails app that I want to use sidekiq on. 我有一个要在其上使用sidekiq的Rails应用程序。

Before I figure out how to setup sidekiq on the server etc., is it possible for me to create a rake task that will run the sidekiq workers for any pending jobs? 在弄清楚如何在服务器等上设置sidekiq之前,我是否可以创建一个rake任务,该任务将为所有未完成的作业运行sidekiq工作者?

This isn't a production solution I know, but I just want to make sure everything else is working on the server and for the time being me running a rake task on the server is fine as it is more for QA'ing at this point. 我知道这不是生产解决方案,但我只想确保服务器上的所有其他功能都可以正常运行,暂时我可以在服务器上运行rake任务很好,因为这对于质量检查而言更为重要。

登录服务器,cd到应用程序的目录,然后手动运行“ bundle exec sidekiq”。

Referencing from SortedEntry and ScheduledSet , I managed to come up with the following: SortedEntryScheduledSet引用,我设法提出以下内容:

# ScheduledSet returns "pending" jobs
scheduled_jobs = Sidekiq::ScheduledSet.new

# puts scheduled_jobs.class
# => Sidekiq::ScheduledSet

scheduled_jobs.each do |scheduled_job|
  # puts scheduled_job.class
  # => Sidekiq::SortedEntry

  job_class = scheduled_job.klass.constantize
  job_args = scheduled_job.args

  # you can also filter out only jobs in certain queue, i.e.:
  # if scheduled_job.queue == 'mailers' ......

  # run the job inline
  job_class.new.perform(*job_args)
end

Then just wrap this into a rake task. 然后将其包装到一个rake任务中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM