Class: FeedNotifier::Runner
- Inherits:
-
Object
- Object
- FeedNotifier::Runner
- Defined in:
- lib/feed_notifier/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #check_and_notify(feed_list) ⇒ Object
- #check_pid ⇒ Object
- #cleanup ⇒ Object
-
#initialize(run_config) ⇒ Runner
constructor
A new instance of Runner.
- #pid_path ⇒ Object
- #run ⇒ Object
- #setup ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/feed_notifier/runner.rb', line 3 def config @config end |
Instance Method Details
#check_and_notify(feed_list) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/feed_notifier/runner.rb', line 53 def check_and_notify(feed_list) FeedNotifier.logger.info "polling feed list..#{feed_list.urls}" entries = feed_list.updated_entries() FeedNotifier.logger.info "updated entries #{entries}" if entries.size > 0 entries.each do |entry| Notifier.notify(entry) end end end |
#check_pid ⇒ Object
10 11 12 13 14 15 |
# File 'lib/feed_notifier/runner.rb', line 10 def check_pid if File.exist?(pid_path) pid = File.read(pid_path) raise "already running process PID:#{pid}" end end |
#cleanup ⇒ Object
17 18 19 20 21 |
# File 'lib/feed_notifier/runner.rb', line 17 def cleanup if File.exist?(pid_path) File.delete(pid_path) end end |
#pid_path ⇒ Object
23 24 25 |
# File 'lib/feed_notifier/runner.rb', line 23 def pid_path File.join(@run_config[:pid_dir],'feed_notifier.pid') end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/feed_notifier/runner.rb', line 40 def run setup do thread = ::Thread.new do feed_list = FeedList.new(config) while true do check_and_notify(feed_list) sleep config.interval end end thread.join end end |
#setup ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/feed_notifier/runner.rb', line 27 def setup if @run_config[:daemon] check_pid Process.daemon if @run_config[:daemon] end begin yield rescue Interrupt => e cleanup end end |