gpt4 book ai didi

ruby-on-rails - delay_job 在生产一段时间后停止运行

转载 作者:行者123 更新时间:2023-12-04 00:57:34 26 4
gpt4 key购买 nike

在生产中,我们的 delayed_job由于某种原因,进程正在死亡。我不确定它是否崩溃或被操作系统杀死或什么。我在 delayed_job.log 中没有看到任何错误文件。

我能做些什么来解决这个问题?我正在考虑安装 monit监视它,但这只会告诉我它何时死亡。它不会真正告诉我它为什么会死。

有没有办法让它对日志文件更健谈,这样我就可以知道它为什么会死?

还有其他建议吗?

最佳答案

我遇到了 delay_job 静默失败的两个原因。第一个是当人们在 fork 进程中使用 libxml 时的实际段错误(这在一段时间前出现在邮件列表中)。

第二个是与 delay_job 所依赖的守护进程的 1.1.0 版本有关的问题( https://github.com/collectiveidea/delayed_job/issues#issue/81 ),这可以通过使用 1.0.10 轻松解决,这是我自己的 Gemfile 中的内容。

日志记录

有登录 delay_job 所以如果工作人员在没有打印错误的情况下死亡,通常是因为它没有抛出异常(例如段错误)或外部的东西正在终止进程。

监控

我使用 bluepill 来监控延迟的作业实例,到目前为止,这在确保作业保持运行方面非常成功。为应用程序运行 bluepill 的步骤非常简单

将 bluepill gem 添加到您的 Gemfile 中:

 # Monitoring
gem 'i18n' # Not sure why but it complained I didn't have it
gem 'bluepill'

我创建了一个 bluepill 配置文件:
app_home = "/home/mi/production"
workers = 5
Bluepill.application("mi_delayed_job", :log_file => "#{app_home}/shared/log/bluepill.log") do |app|
(0...workers).each do |i|
app.process("delayed_job.#{i}") do |process|
process.working_dir = "#{app_home}/current"

process.start_grace_time = 10.seconds
process.stop_grace_time = 10.seconds
process.restart_grace_time = 10.seconds

process.start_command = "cd #{app_home}/current && RAILS_ENV=production ruby script/delayed_job start -i #{i}"
process.stop_command = "cd #{app_home}/current && RAILS_ENV=production ruby script/delayed_job stop -i #{i}"

process.pid_file = "#{app_home}/shared/pids/delayed_job.#{i}.pid"
process.uid = "mi"
process.gid = "mi"
end
end
end

然后在我的 capistrano 部署文件中,我刚刚添加了:
# Bluepill related tasks
after "deploy:update", "bluepill:quit", "bluepill:start"
namespace :bluepill do
desc "Stop processes that bluepill is monitoring and quit bluepill"
task :quit, :roles => [:app] do
run "cd #{current_path} && bundle exec bluepill --no-privileged stop"
run "cd #{current_path} && bundle exec bluepill --no-privileged quit"
end

desc "Load bluepill configuration and start it"
task :start, :roles => [:app] do
run "cd #{current_path} && bundle exec bluepill --no-privileged load /home/mi/production/current/config/delayed_job.bluepill"
end

desc "Prints bluepills monitored processes statuses"
task :status, :roles => [:app] do
run "cd #{current_path} && bundle exec bluepill --no-privileged status"
end
end

希望这会有所帮助。

关于ruby-on-rails - delay_job 在生产一段时间后停止运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4330544/

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