Class: Ryespy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/ryespy/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(eternal = false, opts = {}) ⇒ App

Returns a new instance of App.



45
46
47
48
49
50
51
52
53
54
# File 'lib/ryespy/app.rb', line 45

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

#configObject (readonly)

Returns the value of attribute config.



42
43
44
# File 'lib/ryespy/app.rb', line 42

def config
  @config
end

#runningObject (readonly)

Returns the value of attribute running.



43
44
45
# File 'lib/ryespy/app.rb', line 43

def running
  @running
end

Class Method Details

.config_defaultsObject



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/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
    },
    :rax_cf => {
      :endpoint => :us,
      :region   => :dfw,
      :filters  => [''], # prefixes
    },
  }
end

Instance Method Details

#configure {|@config| ... } ⇒ Object

Yields:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ryespy/app.rb', line 56

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

#notifiersObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ryespy/app.rb', line 68

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

#startObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ryespy/app.rb', line 84

def start
  begin
    @running = true
    
    setup
    
    @threads[:refresh] ||= Thread.new do
      refresh_loop # refresh frequently
    end
    
    @threads.values.each(&:join)
  ensure
    cleanup
  end
end

#stopObject



100
101
102
103
104
# File 'lib/ryespy/app.rb', line 100

def stop
  @running = false
  
  @threads.values.each { |t| t.run if t.status == 'sleep' }
end