Skip to content

Commit

Permalink
Refactor EvmServer#refresh_servers_to_monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
carbonin committed Jan 24, 2020
1 parent 46cb353 commit bddb7fa
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/workers/evm_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ def kill_servers
end

def refresh_servers_to_monitor
# Add the server object to our list and start it if we're not monitoring it already
servers_from_db.each do |db_server|
unless monitoring_server?(db_server)
servers_to_monitor << db_server
impersonate_server(db_server)
start_server
end
servers_to_start = servers_from_db - servers_to_monitor
servers_to_shutdown = servers_to_monitor - servers_from_db

servers_to_start.each do |s|
servers_to_monitor << s
impersonate_server(s)
start_server
end

# Remove and shutdown a server if we're monitoring it and it is no longer in the database
servers_to_monitor.delete_if do |monitor_server|
servers_from_db.none? { |db_server| db_server.id == monitor_server.id }.tap do |should_delete|
monitor_server.shutdown if should_delete
end
servers_to_shutdown.each do |s|
servers_to_monitor.delete(s)
impersonate_server(s)
s.shutdown
end
end

Expand Down

0 comments on commit bddb7fa

Please sign in to comment.