本文介绍了同时运行延迟的作业和Sidekiq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用延迟作业异步处理作业。我没有使用工人,而是大量使用 .delay 方法。

I currently use delayed job to process jobs asynchronously. Instead of creating workers, I use the .delay method a lot.

我想搬到Sidekiq,但是我的工作类型太多,无法确保所有工作都是线程安全的。因此,我想同时运行Delayed Job和Sidekiq,并一次迁移一种类型的作业。

I want to move to Sidekiq, but I have too many types of jobs, and can't make sure all of them are thread safe. So I want to run Delayed Job and Sidekiq in parallel, and migrating one type of job at a time.

由于Delayed Job和Sidekiq均提供了 .delay 方法,如何区分两者?还有其他潜在问题吗?

Since both Delayed Job and Sidekiq offers the .delay method, how can I make the distinction between the two? Are there any other potential issues?

推荐答案

对于Sidekiq 2.17.1及更高版本,在Rails初始化程序中的某个位置,调用以下命令:

For Sidekiq 2.17.1 and later, somewhere in the Rails initializers, call the following:

Sidekiq.hook_rails!
Sidekiq.remove_delay!

,您将只使用前缀 sidekiq_delay 方法

()

对于较旧版本的Sidekiq:

For older versions of Sidekiq:

将以下内容放入 config / initializers / sidekiq.rb

module Sidekiq::Extensions::Klass
  alias :sidekiq_delay :delay
  remove_method :delay
  alias :sidekiq_delay_for :delay_for
  remove_method :delay_for
  alias :sidekiq_delay_until :delay_until
  remove_method :delay_until
end

module Sidekiq::Extensions::ActiveRecord
  alias :sidekiq_delay :delay
  remove_method :delay
  alias :sidekiq_delay_for :delay_for
  remove_method :delay_for
  alias :sidekiq_delay_until :delay_until
  remove_method :delay_until
end

module Sidekiq::Extensions::ActionMailer
  alias :sidekiq_delay :delay
  remove_method :delay
  alias :sidekiq_delay_for :delay_for
  remove_method :delay_for
  alias :sidekiq_delay_until :delay_until
  remove_method :delay_until
end

然后可以使用 sidekiq_delay 在Sidekiq中排队,然后调用 delay 在延迟作业中排队。

And then you can use sidekiq_delay to queue in Sidekiq, and call delay to queue in Delayed Job.

这篇关于同时运行延迟的作业和Sidekiq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 11:30