From b10171b89a1666591102aca3be76f254351edde7 Mon Sep 17 00:00:00 2001 From: uu59 Date: Mon, 7 Jul 2014 10:52:11 +0900 Subject: [PATCH] Refactor updating fluentd-ui --- app/controllers/misc_controller.rb | 9 ++++++++- app/workers/fluentd_ui_restart.rb | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/misc_controller.rb b/app/controllers/misc_controller.rb index 6a71c33..b90a305 100644 --- a/app/controllers/misc_controller.rb +++ b/app/controllers/misc_controller.rb @@ -1,6 +1,8 @@ require "fluent/version" class MiscController < ApplicationController + after_action :update!, only: [:update_fluentd_ui] + def show redirect_to misc_information_path end @@ -11,7 +13,6 @@ class MiscController < ApplicationController end def update_fluentd_ui - FluentdUiRestart.new.async.perform @current_pid = $$ render "update_fluentd_ui", layout: "sign_in" end @@ -29,4 +30,10 @@ class MiscController < ApplicationController render text: "finished" end end + + private + + def update! + FluentdUiRestart.new.async.perform + end end diff --git a/app/workers/fluentd_ui_restart.rb b/app/workers/fluentd_ui_restart.rb index 5ce7258..5b40744 100644 --- a/app/workers/fluentd_ui_restart.rb +++ b/app/workers/fluentd_ui_restart.rb @@ -4,8 +4,12 @@ class FluentdUiRestart LOCK = [] def lock! - raise "update process is still running" if LOCK.present? - LOCK << true + raise "update process is still running" if locked? + LOCK << true # dummy value + end + + def locked? + LOCK.present? end def unlock! @@ -14,7 +18,6 @@ class FluentdUiRestart def perform lock! - sleep 5 # delay for render updating HTML # NOTE: install will be failed before released fluentd-ui gem SuckerPunch.logger.info "[restart] install new fluentd-ui"