add graceful shutdown
This commit is contained in:
parent
84c684b182
commit
5f8bcd2ffa
@ -19,6 +19,10 @@ class Folder
|
||||
end
|
||||
end
|
||||
|
||||
def close()
|
||||
self.update()
|
||||
end
|
||||
|
||||
def num_subs()
|
||||
@submissions.length
|
||||
end
|
||||
|
22
main.rb
22
main.rb
@ -10,6 +10,8 @@ require 'logger'
|
||||
require 'astro/moon'
|
||||
require './folder.rb'
|
||||
|
||||
|
||||
|
||||
logger = Logger.new(STDOUT)
|
||||
logger.level = Logger::INFO
|
||||
|
||||
@ -17,6 +19,16 @@ config_obj = YAML::load_file( './config.yaml' )
|
||||
logger.info("loaded config")
|
||||
bot = Discordrb::Commands::CommandBot.new token: config_obj["bot_token"], prefix: "!folder"
|
||||
folder = Folder.new
|
||||
|
||||
def shutdown
|
||||
log.info("shutting down")
|
||||
if bot.connected
|
||||
bot.stop
|
||||
end
|
||||
folder.close
|
||||
end
|
||||
|
||||
|
||||
config_obj['steves'].each do |steve|
|
||||
folder.add_steve(steve)
|
||||
end
|
||||
@ -89,7 +101,17 @@ bot.message(private: true) do |event|
|
||||
folder.update()
|
||||
end
|
||||
|
||||
#set up signals
|
||||
Signal.trap("INT") {
|
||||
shut_down
|
||||
exit
|
||||
}
|
||||
|
||||
# Trap `Kill `
|
||||
Signal.trap("TERM") {
|
||||
shut_down
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
logger.info("Logging into discord")
|
||||
|
Loading…
Reference in New Issue
Block a user