Ruby-on-rails Rails:如何重新启动sidekiq?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24446157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:45:10  来源:igfitidea点击:

Rails: How to restart sidekiq?

ruby-on-railsrubyruby-on-rails-3sidekiq

提问by Can Can

I am using sidekiq gem to run API calls in background. I ran sidekiq in Daemon process like:

我正在使用 sidekiq gem 在后台运行 API 调用。我在守护进程中运行 sidekiq,如:

  bundle exec sidekiq -d

Now I made some changes in my method, so I want to restart sidekiq. I tried to kill the sidekiq by using the below command:

现在我对我的方法做了一些改变,所以我想重新启动 sidekiq。我尝试使用以下命令杀死 sidekiq:

  kill -9 process_id 

but it's not working. I want to know the command to restart sidekiq process. If you have any idea please share with me.

但它不起作用。我想知道重启 sidekiq 进程的命令。如果您有任何想法,请与我分享。

I tried the below command also:

我也尝试了以下命令:

 sidekiqctl stop /path/to/pid file/pids/sidekiq.pid

采纳答案by alexsmn

So after you find you proces_id, use the below command, that will stop the workers from getting new jobs, and they will finish existing jobs.

所以在你找到你的proces_id之后,使用下面的命令,这将阻止工人获得新的工作,他们将完成现有的工作。

kill -USR1 [PROCESS_ID]

After that you can kill them

之后你可以杀死他们

kill -TERM [PROCESS_ID]

Also there is a page on sidekiq/wiki about this, called Signals.

在 sidekiq/wiki 上还有一个关于此的页面,称为 Signals。

[edit]

[编辑]

Hereis the signal page.

是信号页面。

[edit]

[编辑]

Check video

检查视频

回答by hlcs

Start:

开始:

$ bundle exec sidekiq -d -P tmp/sidekiq.pid -L log/sidekiq.log 

where -ddemonize, -Ppid file, -Llog file.

其中-d恶魔化,-Ppid 文件,-L日志文件。

Stop:

停止:

$ bundle exec sidekiqctl stop tmp/sidekiq.pid 0
Sidekiq shut down gracefully.

where 0is number of seconds to wait until Sidekiq exits.

其中0是等待 Sidekiq 退出的秒数。

回答by Jonathan Reyes

To keep the daemon running you should definitely have some good error handling in the HardWorker classes, but you can also use the command below to restart the sidekiq runners if they are not found in the system processes.

要保持守护进程运行,您肯定应该在 HardWorker 类中进行一些良好的错误处理,但是如果在系统进程中找不到 sidekiq 运行程序,您也可以使用下面的命令重新启动它们。

x=`ps aux | grep sidekiq | grep -v grep | awk '{print }'`; [ "$x" == "" ] && cd /path/to/deploy && bundle exec sidekiq -d -L /path/to/deploy/log/sidekiq.log -C /path/to/deploy/config/sidekiq.yml -e production

This basically looks for the PID using ps aux | grep sidekiq | grep -v grep | awk '{print $2}'and then stores it in variable x. Then, if it's empty, it will run a daemonized sidekiq process.

这基本上是使用 PID 查找ps aux | grep sidekiq | grep -v grep | awk '{print $2}',然后将其存储在变量中x。然后,如果它是空的,它将运行一个守护进程的 sidekiq 进程。

You can stick this guy into a cron job or something. But if your jobs are failing continually, you'll definitely want to figure out why.

你可以让这个人从事一项 cron 工作或其他事情。但是,如果您的工作不断失败,您肯定想找出原因。

EDIT: Added path to deploy from cron.

编辑:添加了从 cron 部署的路径。

回答by user3133204

  1. Type in following command: ps -ef | grep sidekiqThis gives process_id and other details of running sidekiq process in background.
  2. Copy process_id and use following command: kill process_id
  3. Use following command to start sidekiq again in background with -d option: bundle exec sidekiq -d -L log/sidekiq.log
  1. 输入以下命令: ps -ef | grep sidekiq这给出了在后台运行 sidekiq 进程的 process_id 和其他详细信息。
  2. 复制 process_id 并使用以下命令: kill process_id
  3. 使用以下命令在后台使用 -d 选项再次启动 sidekiq: bundle exec sidekiq -d -L log/sidekiq.log