From a92f7b2153cc5ca36c047187f6b77e5992da3ee8 Mon Sep 17 00:00:00 2001 From: Jens Pfeifer Date: Thu, 13 Dec 2018 15:40:22 +0100 Subject: [PATCH] Migrated AppVersionRestartJob to Active Job. --- app/jobs/app_version_restart_job.rb | 7 +++++++ app/models/object_manager/attribute.rb | 2 +- app/models/observer/app_version_restart_job.rb | 11 ----------- spec/jobs/app_version_restart_job_spec.rb | 11 +++++++++++ 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 app/jobs/app_version_restart_job.rb delete mode 100644 app/models/observer/app_version_restart_job.rb create mode 100644 spec/jobs/app_version_restart_job_spec.rb diff --git a/app/jobs/app_version_restart_job.rb b/app/jobs/app_version_restart_job.rb new file mode 100644 index 000000000..daf24eb38 --- /dev/null +++ b/app/jobs/app_version_restart_job.rb @@ -0,0 +1,7 @@ +class AppVersionRestartJob < ApplicationJob + def perform(cmd) + Rails.logger.info "executing CMD: #{cmd}" + ::Kernel.system(cmd) + Rails.logger.info "executed CMD: #{cmd}" + end +end diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 10042bdc8..6b86dae8d 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -768,7 +768,7 @@ to send no browser reload event, pass false if ENV['APP_RESTART_CMD'] AppVersion.set(true, 'restart_auto') sleep 4 - Delayed::Job.enqueue(Observer::AppVersionRestartJob.new(ENV['APP_RESTART_CMD'])) + AppVersionRestartJob.perform_later(ENV['APP_RESTART_CMD']) else AppVersion.set(true, 'restart_manual') end diff --git a/app/models/observer/app_version_restart_job.rb b/app/models/observer/app_version_restart_job.rb deleted file mode 100644 index 8dcc43e35..000000000 --- a/app/models/observer/app_version_restart_job.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Observer::AppVersionRestartJob - def initialize(cmd) - @cmd = cmd - end - - def perform - Rails.logger.info "executing CMD: #{@cmd}" - system(@cmd) - Rails.logger.info "executed CMD: #{@cmd}" - end -end diff --git a/spec/jobs/app_version_restart_job_spec.rb b/spec/jobs/app_version_restart_job_spec.rb new file mode 100644 index 000000000..1e637714d --- /dev/null +++ b/spec/jobs/app_version_restart_job_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe AppVersionRestartJob, type: :job do + + let(:cmd) { '/path/to/restart_script.sh' } + + it 'executes app version restart job' do + expect(::Kernel).to receive(:system).with(cmd) + described_class.perform_now(cmd) + end +end