Class: FluentdUiRestartJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- FluentdUiRestartJob
- Defined in:
- app/jobs/fluentd_ui_restart_job.rb
Constant Summary collapse
- LOCK =
[]
Instance Method Summary collapse
Instance Method Details
#lock! ⇒ Object
6 7 8 9 |
# File 'app/jobs/fluentd_ui_restart_job.rb', line 6 def lock! raise "update process is still running" if locked? LOCK << true # dummy value end |
#locked? ⇒ Boolean
11 12 13 |
# File 'app/jobs/fluentd_ui_restart_job.rb', line 11 def locked? LOCK.present? end |
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/jobs/fluentd_ui_restart_job.rb', line 19 def perform lock! # NOTE: install will be failed before released fluentd-ui gem logger.info "[restart] install new fluentd-ui" Plugin.new(gem_name: "fluentd-ui").install! if Rails.env.production? cmd = %W(#{Rails.root}/bin/fluentd-ui start) else cmd = %W(bundle exec rails s) end logger.info "[restart] will restart" Bundler.with_clean_env do restarter = "#{Rails.root}/bin/fluentd-ui-restart" Process.spawn(*[restarter, $$.to_s, *cmd, *ARGV]) && Process.kill(:TERM, $$) end ensure # don't reach here if restart is successful unlock! end |
#unlock! ⇒ Object
15 16 17 |
# File 'app/jobs/fluentd_ui_restart_job.rb', line 15 def unlock! LOCK.shift end |