Class: Ryespy::App
- Inherits:
-
Object
- Object
- Ryespy::App
- Defined in:
- lib/ryespy/app.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
Class Method Summary collapse
Instance Method Summary collapse
- #configure {|@config| ... } ⇒ Object
-
#initialize(eternal = false, opts = {}) ⇒ App
constructor
A new instance of App.
- #notifiers ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(eternal = false, opts = {}) ⇒ App
Returns a new instance of App.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ryespy/app.rb', line 48 def initialize(eternal = false, opts = {}) @eternal = eternal @logger = opts[:logger] || Logger.new(nil) @config = OpenStruct.new(self.class.config_defaults) @running = false @threads = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
45 46 47 |
# File 'lib/ryespy/app.rb', line 45 def config @config end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
46 47 48 |
# File 'lib/ryespy/app.rb', line 46 def running @running end |
Class Method Details
.config_defaults ⇒ Object
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 41 42 43 |
# File 'lib/ryespy/app.rb', line 12 def self.config_defaults { :log_level => :INFO, :polling_interval => 60, :redis_ns_ryespy => 'ryespy', :redis_ns_notifiers => 'resque', :imap => { :port => 993, :ssl => true, :filters => ['INBOX'], # mailboxes }, :ftp => { :port => 21, :passive => false, :filters => ['/'], # dirs }, :amzn_s3 => { :filters => [''], # prefixes }, :goog_cs => { :filters => [''], # prefixes }, :goog_drv => { :filters => [''], }, :rax_cf => { :endpoint => :us, :region => :dfw, :filters => [''], # prefixes }, } end |
Instance Method Details
#configure {|@config| ... } ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ryespy/app.rb', line 59 def configure yield @config @logger.level = Logger.const_get(@config.log_level) Redis.current = Redis::Namespace.new(@config.redis_ns_ryespy, :redis => Redis.connect(:url => @config.redis_url) ) @logger.debug { "Configured #{@config.to_s}" } end |
#notifiers ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ryespy/app.rb', line 71 def notifiers unless @notifiers @notifiers = [] @config.notifiers[:sidekiq].each do |notifier_url| @notifiers << Notifier::Sidekiq.new( :url => notifier_url, :namespace => @config.redis_ns_notifiers, :logger => @logger ) end end @notifiers end |
#start ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ryespy/app.rb', line 86 def start begin @running = true setup @threads[:refresh] ||= Thread.new do refresh_loop # refresh frequently end @threads.values.each(&:join) ensure cleanup end end |
#stop ⇒ Object
102 103 104 105 106 |
# File 'lib/ryespy/app.rb', line 102 def stop @running = false @threads.values.each { |t| t.run if t.status == 'sleep' } end |