ruby – 重新启动Sidekiq

前端之家收集整理的这篇文章主要介绍了ruby – 重新启动Sidekiq前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



什么是正确的方式重新启动sidekiq.当我启动它时,似乎缓存了我的工作人员的代码,所以每当我改变我的工作人员时,我需要重新启动它.我使用Ctrl / C进行此操作,但该过程需要很长时间才能关闭并返回到提示.

有没有办法强制重新启动立即生效?

我正在使用Sinatra通过POW运行的最新版本.

解决方法

Sidekiq附带命令sidekiqctl,可以停止与您的Sidekiq进程相关联的PID.您传入PID文件和秒数等待所有线程完成.

样品用法

sidekiqctl stop #{rails_root}/tmp/pids/sidekiq_website_crawler.pid 60

这里,60表示等待所有Sidekiq线程完成处理的秒数.如果60秒通过,并且全部没有完成,它们将被自动杀死.

我还建议使用神宝来监视,停止,启动和重新启动Sidekiq.

一旦你这样做,你可以使用bundle exec god stop来停止所有sidekiq线程.

这是我的神文件,例如:

rails_env = ENV['RAILS_ENV'] || "development"
rails_root = ENV['RAILS_ROOT'] || "/home/hwc218/BuzzSumo"
 God.watch do |w|
     w.dir      = "#{rails_root}"
     w.name     = "website_crawler"
     w.interval = 30.seconds
     w.env      = {"RAILS_ENV" => rails_env}
     w.interval = 30.seconds
     w.start = "bundle exec sidekiq -C #{rails_root}/config/sidekiq_website_crawler.yml"
     w.stop = "sidekiqctl stop #{rails_root}/tmp/pids/sidekiq_website_crawler.pid 60"
     w.keepalive


    # determine the state on startup
     w.transition(:init,{ true => :up,false => :start }) do |on|
    on.condition(:process_running) do |c|
      c.running = true
    end
    end

     # determine when process has finished starting
      w.transition([:start,:restart],:up) do |on|
      on.condition(:process_running) do |c|
      c.running = true
      c.interval = 5.seconds
    end

      # failsafe
       on.condition(:tries) do |c|
      c.times = 5
      c.transition = :start
      c.interval = 5.seconds
     end
    end

    # start if process is not running
     w.transition(:up,:start) do |on|
    on.condition(:process_running) do |c|
      c.running = false
    end
    end

    w.restart_if do |restart|
        restart.condition(:restart_file_touched) do |c|
          c.interval = 5.seconds
          c.restart_file = File.join(rails_root,'tmp','restart.txt')
        end
    end
 end
原文链接:https://www.f2er.com/ruby/273500.html

猜你在找的Ruby相关文章