gpt4 book ai didi

ruby-on-rails - 使用 sidekiq-unique-jobs gem

转载 作者:行者123 更新时间:2023-12-03 14:37:49 26 4
gpt4 key购买 nike

我正在尝试使用 sidekiq-unique-jobs 但老实说无法让它做任何它应该做的事情。
我试图使同一作业无法多次排队(虽然它已经在队列中或正在运行),但正如您在此处看到的,我启动了具有相同 ID 的 worker 3 次,并且每次都运行。
rails 5.2.1
Sidekiq 6.0.6
有任何想法吗?
这是 worker :

class RefreshLoginWorker

include Sidekiq::Worker
include Sidekiq::Status::Worker

sidekiq_options queue: 'credentials', :retry => false, lock: :until_executed

def perform item_id
sleep 5
end

end
在这里,我们一个接一个地开始一些工作:
irb(main):016:0> RefreshLoginWorker.perform_async 20
=> "4e83f7a419b9aa047860af77"
irb(main):017:0> RefreshLoginWorker.perform_async 20
=> "682776c2fb45866f35cbf87f"
irb(main):018:0> RefreshLoginWorker.perform_async 20
=> "962dc0bae18cfc4ede6aea18"
Sidekiq 日志:
2020-07-18T17:30:48.468Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=4e83f7a419b9aa047860af77 INFO: start
2020-07-18T17:30:49.060Z pid=561643 tid=gpbejy9vf class=RefreshLoginWorker jid=682776c2fb45866f35cbf87f INFO: start
2020-07-18T17:30:53.469Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=4e83f7a419b9aa047860af77 elapsed=5.001 INFO: done
2020-07-18T17:30:53.470Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=962dc0bae18cfc4ede6aea18 INFO: start
2020-07-18T17:30:54.061Z pid=561643 tid=gpbejy9vf class=RefreshLoginWorker jid=682776c2fb45866f35cbf87f elapsed=5.001 INFO: done
2020-07-18T17:30:58.471Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=962dc0bae18cfc4ede6aea18 elapsed=5.001 INFO: done

最佳答案

首先使用gem 'sidekiq-unique-jobs'然后 bundle .安装后,您应该使用 SidekiqUniqueJobs.config.enabled 启用 sidekiq-unique-jobs .更多详情请关注 sidekiq-unique-jobs

关于ruby-on-rails - 使用 sidekiq-unique-jobs gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62971669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com