Skip to content

Commit

Permalink
fix: reset pid if worker stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
isqad committed Dec 26, 2018
1 parent 49a3422 commit b0d9c1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 0 additions & 2 deletions lib/treasury/supervisor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module Treasury
class Supervisor
STATE_RUNNING = 'running'.freeze
Expand Down
17 changes: 15 additions & 2 deletions lib/treasury/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/treasury/worker.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# coding: utf-8

module Treasury
class Worker
STATE_RUNNING = 'running'.freeze
Expand Down

0 comments on commit b0d9c1c

Please sign in to comment.