From b0d9c1cdab85f19d54b26ade5de8a9938c3767a5 Mon Sep 17 00:00:00 2001 From: "Andrew N. Shalaev" Date: Fri, 21 Dec 2018 17:10:54 +0500 Subject: [PATCH] fix: reset pid if worker stopped --- lib/treasury/supervisor.rb | 2 -- lib/treasury/utils.rb | 17 +++++++++++++++-- lib/treasury/worker.rb | 2 -- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/treasury/supervisor.rb b/lib/treasury/supervisor.rb index 58bd47a..b4b8ad4 100644 --- a/lib/treasury/supervisor.rb +++ b/lib/treasury/supervisor.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - module Treasury class Supervisor STATE_RUNNING = 'running'.freeze diff --git a/lib/treasury/utils.rb b/lib/treasury/utils.rb index d79ece7..b452d54 100644 --- a/lib/treasury/utils.rb +++ b/lib/treasury/utils.rb @@ -65,9 +65,15 @@ def check_state(state) def set_state(state) return set_session if check_state(state) && process_is_alive?(@process_object.pid) + @process_object.state = state - set_session - @process_object.save! + + if state == 'stopped' + reset_session + else + set_session + end + logger.info "Установлен статус %s" % [quote(@process_object.state)] end @@ -77,6 +83,13 @@ def set_session logger.info "Установлен PID %s" % [quote(@process_object.pid)] end + def reset_session + @process_object.pid = nil + @process_object.save! + + logger.info 'PID сброшен' + end + def save_error(error_message) error_message = error_message[1, 4000] unless error_message.nil? @process_object.last_error = error_message diff --git a/lib/treasury/worker.rb b/lib/treasury/worker.rb index ba09690..3d82ac2 100644 --- a/lib/treasury/worker.rb +++ b/lib/treasury/worker.rb @@ -1,5 +1,3 @@ -# coding: utf-8 - module Treasury class Worker STATE_RUNNING = 'running'.freeze