Permalink
Browse files

React predictably to CTRL-C

  • Loading branch information...
1 parent b1e750b commit 1c0c16039d2f897b151f7b9c8f9a80d14a6de4c8 @tobi tobi committed Jul 9, 2008
Showing with 19 additions and 7 deletions.
  1. +19 −7 backfire.rb
View
@@ -1,12 +1,15 @@
require 'lib/tinder/lib/tinder'
require 'lib/backpack_api_wrapper'
require 'rubygems'
-require 'active_support'
+require 'active_support'
+
module Backfire
LAST_UPDATED_AT_FILE='last_updated_at'
CONFIG_FILE='config.yml'
- @@last_updated_at = nil
+ @@last_updated_at = nil
+
+ mattr_accessor :exit
def self.config
@@config ||= YAML.load(File.read(CONFIG_FILE))
@@ -81,10 +84,15 @@ def self.update_campfire
self.is_now_updated
end
- def self.go(interval = 20)# seconds
- while true
- update_campfire
- sleep interval
+ def self.go(interval = 20)# seconds
+ puts 'Starting backfire'
+ last_run = Time.now
+ while not exit
+ if last_run - Time.now > interval
+ update_campfire
+ last_run = Time.now
+ end
+ sleep 5
end
end
@@ -138,6 +146,10 @@ def self.all
end
-end # module Backfire
+end # module Backfire
+
+trap('TERM') { puts 'Exiting...'; Backfire.exit = true }
+trap('INT') { puts 'Exiting...'; Backfire.exit = true }
+
Backfire.go(Backfire.config['global']['interval'])

0 comments on commit 1c0c160

Please sign in to comment.