Class: DiscordRDA::RestartManager
- Inherits:
-
Object
- Object
- DiscordRDA::RestartManager
- Defined in:
- lib/discord_rda/core/restart_manager.rb
Constant Summary collapse
- STATE_ENV =
'DISCORD_RDA_RESTART_STATE_PATH'
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #attach(bot) ⇒ Object
- #consume_boot_state ⇒ Object
-
#initialize(logger:) ⇒ RestartManager
constructor
A new instance of RestartManager.
- #restart!(command: nil, env: {}) ⇒ Object
Constructor Details
#initialize(logger:) ⇒ RestartManager
Returns a new instance of RestartManager.
14 15 16 17 |
# File 'lib/discord_rda/core/restart_manager.rb', line 14 def initialize(logger:) @logger = logger @bot = nil end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/discord_rda/core/restart_manager.rb', line 12 def logger @logger end |
Instance Method Details
#attach(bot) ⇒ Object
19 20 21 |
# File 'lib/discord_rda/core/restart_manager.rb', line 19 def attach(bot) @bot = bot end |
#consume_boot_state ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/discord_rda/core/restart_manager.rb', line 23 def consume_boot_state path = ENV.delete(STATE_ENV) return {} unless path && File.exist?(path) data = JSON.parse(File.read(path)) File.delete(path) logger&.info('Loaded restart state', shards: (data['shards'] || []).length) data rescue StandardError => e logger&.error('Failed to load restart state', error: e) {} end |
#restart!(command: nil, env: {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/discord_rda/core/restart_manager.rb', line 36 def restart!(command: nil, env: {}) raise 'Restart manager is not attached to a bot instance' unless @bot state_path = write_restart_state restart_command = command || default_command logger&.info('Performing instant restart', command: restart_command) exec( { STATE_ENV => state_path, 'DISCORD_RDA_RESTARTED_AT' => Time.now.utc.iso8601 }.merge(env), RbConfig.ruby, *restart_command ) end |