Module: Maidservice::Listener
- Defined in:
- lib/maidservice/listener.rb
Class Method Summary collapse
-
.clear_page(full_path) ⇒ Object
TODO: scary powerful.
-
.run ⇒ Object
Daemon that runs and listens.
Class Method Details
.clear_page(full_path) ⇒ Object
TODO: scary powerful. Protect against bad ideas
43 44 45 46 47 |
# File 'lib/maidservice/listener.rb', line 43 def self.clear_page(full_path) return unless ActionController::Base.perform_caching FileUtils.rm_rf(full_path) if File.exist?(full_path) File.delete(full_path + '.gz') if File.exist?(full_path + '.gz') end |
.run ⇒ Object
Daemon that runs and listens
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/maidservice/listener.rb', line 5 def self.run trap("TERM") { exit } $0 = "Maidservice: Starting" # get output from the child in there. $stdout.sync = true $stderr.sync = true redis = Maidservice.redis begin redis.subscribe('expire_page.action_controller') do |on| on.subscribe do |channel, subscriptions| puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)" end on. do |channel, | puts "##{channel}: #{message}" clear_page() end on.unsubscribe do |channel, subscriptions| puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)" end end rescue ::Redis::BaseConnectionError => error puts "#{error}, retrying in 1s" sleep 1 retry end # never gets here. end |