运行Sidekiq几个小时后,我看到许多作业在Mysql2::Error: This connection is in use by: #<Celluloid::Thread:0x0000000d1b56e0 sleep>中失败。似乎Sidekiq线程在MySQL连接池上有些冲突。
concurrency在sidekiq.yml中设置为默认的25,在database.yml中池设置为28。没有长时间的查询,在标准的finder调用中也会出现异常,没有什么特别之处。
如何防止此错误以确保作业顺利运行?
我有两个Sidekiq工人:
Foo:
# frozen_string_literal: true
class FooWorker
include Sidekiq::Worker
sidekiq_options queue: :foo
def perform
loop do
File.open(File.join(Rails.root, 'foo.txt'), 'w') { |file| file.write('FOO') }
end
end
end
酒吧:
# f
我需要对我的Sidekiq作业进行节流,这样我就不会遇到这种失败: 2020-04-23T12:36:24.424Z pid=1 tid=osrlydn8x WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were in use 基本上,我要做的是发送许
我正在开发一个在nginx负载均衡器后面有多个rails服务器的生产应用程序。我们正在使用monit监控sidekiq进程,它工作得很好--当sidekiq进程死掉时,monit会立即重新启动它。
然而,最近遇到了这样一种情况,其中一个进程正在运行,对monit可见,但由于某种原因,对sidekiq不可见。这导致了许多失败的作业,并花了我们一些时间来注意到我们在sidekiq Web UI中遗漏了一个进程,因为monit告诉我们一切都很好,所有的进程都在运行。简单的重新启动解决了这个问题。
这就引出了我的问题:你如何监控你的sidekiq进程?我知道我可以使用rollbar之类的工具在作业失败
我有一个rails应用程序,它使用了sidekiq、sidekiq-status和sidekiq批处理:
gem "sidekiq"
gem "sidekiq-status"
# freemium version vs sidekiq pro https://github.com/breamware/sidekiq-batch
gem "sidekiq-batch"
# slim & sinatra for sidekiq monitoring
gem "sinatra", "2.0.0.beta2", r
我的Sidekiq工人如下所示:
Class BooksWorker
include Sidekiq::Worker
def perform
books = Book.where(collected: true)
books.each do |book|
book.update_attribute(:status, "read")
book.toggle!(:collected)
end
end
end
我想使用禁用模式下的Sidekiq测试来检查:
作业是排队的
Sidekiq与Redis
我有一个每4分钟运行一次的Sidekiq作业。
此作业在再次执行代码之前检查当前代码块是否正在执行。
process = ProcessTime.where("name = 'ad_queue_process'").first
# Return if job is running
return if process.is_running == true
如果Sidekiq在代码块中间重新启动,则更新作业状态的代码永远不会运行。
# Done running, update the process times and allow it to be ran aga
我在我的应用程序中使用Rails 6,附带了Sidekiq。我得到的FetchAllProductsWorker如下所示:
module Imports
class FetchAllProductsWorker
include Sidekiq::Worker
sidekiq_options queue: 'imports_fetch_all', retry: 0
def perform
(...)
end
end
end
我想检查FetchAllProductsWorker上次成功完成的时间,并在我的前端显示这个信息。此作业
在创建记录后,我正在使用sidekiq运行一些作业。当作业尝试查找具有创建的ID的记录时,它会随机引发一个RecordNotFound。这怎么可能呢?
class Person
def self.test_create
p = Person.create(
name: 'test'
)
p.run_on_sidekiq
end
def run_on_sidekiq
PersonJob.perform_async(self.id)
end
end
# Sidekiq runs on other server.
cl