ryespy 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9950cd62c7ec9aea8a7b08fb0c1cfbfdcdee22e9
4
- data.tar.gz: 4ac0a03ecbff1abf251f528f5c46ca5f9c024534
3
+ metadata.gz: 860859af5bd69be0921657d6474f6b4a96a94495
4
+ data.tar.gz: 3e71c677ffc60afd566c7950c10c46213bb7122f
5
5
  SHA512:
6
- metadata.gz: b3267a88b15e58b90813a5842ed494f7c1aa49b30bbc3da4f6eaa56b9b3cf36281356006fda06531810a47d916bb1efc77d5af86f050039684ad92ffd3cdbace
7
- data.tar.gz: 76c90341a60f6c9213e9e5fb8a7c5531434e3e410f93b1e373bcad9cb74e49f443059510ade46d9fa5a28a61a6a4b326fb6646d94b081649c568ba7a05251b84
6
+ metadata.gz: 156f53787df7235da1fc0ebfaeedddb1bdb717cb8b83e82a28f6d147f3c1eff3fe496db1b7a47c667c63f014703995241c625a38e071168845beaefbb04f13d3
7
+ data.tar.gz: f0d64d17a01bedc762af9e778c5f3610ba37bbbeda92ba1e0582fc609141fc7c687a5e9287d1dd39427862d0e2ec8889282805e9e33371f4c5d0112611c9d7b2
@@ -1 +1 @@
1
- ruby-2.0.0-p0
1
+ ruby-2.1.0
@@ -1,5 +1,19 @@
1
1
  language: ruby
2
+ before_install:
3
+ - "gem install bundler -v '~> 1.5, != 1.5.0'"
2
4
  rvm:
5
+ - 2.1.0
3
6
  - 2.0.0
4
7
  - 1.9.3
5
- - 1.9.2
8
+ - jruby-19mode
9
+ - rbx-2.1.1
10
+ services:
11
+ - redis-server
12
+ notifications:
13
+ email:
14
+ recipients:
15
+ - tp@tiredpixel.com
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: jruby-19mode
19
+ - rvm: rbx-2.1.1
@@ -0,0 +1,24 @@
1
+ # Ryespy Changelog
2
+
3
+ This changelog documents the main changes between released versions.
4
+ For a full list of changes, consult the commit history.
5
+ For many of commits by [tiredpixel](http://www.tiredpixel.com), the commit
6
+ message provides information and examples.
7
+
8
+
9
+ ## 1.0.0
10
+
11
+ - first major release; Redis key structure frozen
12
+ - Redis key structure backwards-incompatible with 0.x.x (sorry! :( )
13
+ - start of support for Ruby 2.1.0
14
+ - end of support for Ruby 1.9.2
15
+ - new Amazon S3 listener (`--listener amzn-s3`)
16
+ - new Google Cloud Storage listener (`--listener goog-cs`)
17
+ - new Rackspace Cloud Files listener (`--listener rax-cf`)
18
+ - change of `--verbose` mode to `--debug` mode
19
+ - broader error-catching, in case weird things happen when `--eternal`
20
+ - missing FTP listener (`--listener ftp`) `--ftp-port` fix
21
+ - dynamic requiring of listeners (some have their own dependencies)
22
+ - comprehensive `README` with lots of examples
23
+ - major refactoring and improvement of code throughout
24
+ - a plethora of tests; most of the core is now covered
data/README.md CHANGED
@@ -1,17 +1,27 @@
1
1
  # Ryespy
2
2
 
3
- Ryespy provides a simple executable for listening to IMAP mailboxes or FTP
4
- folders, keeps track of what it's seen using Redis, and notifies Redis in a way
5
- in which [Resque](https://github.com/resque/resque) and
6
- [Sidekiq](https://github.com/mperham/sidekiq) can process using workers.
7
-
8
- Ryespy was inspired by [Redimap](https://github.com/tiredpixel/redimap). Yes,
9
- it's sometimes possible to inspire oneself. Ryespy with my little eye.
3
+ [![Gem Version](https://badge.fury.io/rb/ryespy.png)](http://badge.fury.io/rb/ryespy)
4
+ [![Build Status](https://travis-ci.org/tiredpixel/ryespy.png?branch=master,stable)](https://travis-ci.org/tiredpixel/ryespy)
5
+ [![Code Climate](https://codeclimate.com/github/tiredpixel/ryespy.png)](https://codeclimate.com/github/tiredpixel/ryespy)
6
+
7
+ [Sidekiq](https://github.com/mperham/sidekiq)/[Resque](https://github.com/resque/resque)
8
+ IMAP, FTP, Amazon S3, Google Cloud Storage, Rackspace Cloud Files listener.
9
+
10
+ Ryespy provides an executable for listening to
11
+ IMAP mailboxes,
12
+ FTP folders,
13
+ Amazon S3 buckets,
14
+ Google Cloud Storage buckets,
15
+ or Rackspace Cloud Files containers,
16
+ keeps track of what it's seen using [Redis](http://redis.io), and writes
17
+ Sidekiq/Resque-compatible payloads.
18
+
19
+ Ryespy was inspired by [Redimap](https://github.com/tiredpixel/redimap).
20
+ Yes, it's sometimes possible to inspire oneself.
21
+ Ryespy with my little eye.
10
22
 
11
23
  More sleep lost by [tiredpixel](http://www.tiredpixel.com).
12
24
 
13
- [![Build Status](https://travis-ci.org/tiredpixel/ryespy.png?branch=master,develop)](https://travis-ci.org/tiredpixel/ryespy)
14
-
15
25
 
16
26
  ## Installation
17
27
 
@@ -19,54 +29,165 @@ Install using:
19
29
 
20
30
  $ gem install ryespy
21
31
 
32
+ These externals are required:
33
+
34
+ - [Redis](http://redis.io)
35
+
36
+ Listener dependencies are required dynamically. That means that it may be necessary to manually install the indicated gems if you are using that listener. If you are not using that listener, there should be no need to install the dependencies.
37
+
38
+ - `--listener amzn-s3` :
39
+
40
+ $ gem install fog -v '~> 1.19'
41
+
42
+ - `--listener goog-cs` :
43
+
44
+ $ gem install fog -v '~> 1.19'
45
+
46
+ - `--listener rax-cf` :
47
+
48
+ $ gem install fog -v '~> 1.19'
49
+
22
50
 
23
51
  ## Usage
24
52
 
25
53
  View the available options:
26
54
 
27
- $ bundle exec ryespy --help
55
+ $ ryespy --help
56
+
57
+ It is necessary to specify a listener and at least one notifier. Currently, the only notifier is `--notifier-sidekiq` (this must be specified).
58
+
59
+ The `--help` is most helpful.
60
+
61
+ Use `--eternal` to run eternally (no need for Cron).
62
+
63
+
64
+ ### IMAP Listener
65
+
66
+ Check IMAP, queue new email UIDs, and quit (maybe for Cron):
67
+
68
+ $ ryespy --listener imap --imap-host mail.example.com --imap-username a@example.com --imap-password helpimacarrot --notifier-sidekiq
69
+
70
+ For non-SSL, use `--no-imap-ssl`. For non-INBOX or multiple mailboxes, use `--imap-mailboxes INBOX,Sent`.
71
+
72
+ ### FTP Listener
73
+
74
+ Check FTP, queue new file paths, and quit (maybe for Cron):
75
+
76
+ $ ryespy --listener ftp --ftp-host ftp.example.com --ftp-username b@example.com --ftp-password helpimacucumber --notifier-sidekiq
77
+
78
+ For PASSIVE mode, use `--ftp-passive`. For non-root or multiple directories, use `--ftp-dirs /DIR1,/DIR2`.
79
+
80
+ ### Amazon S3 Listener
81
+
82
+ Check Amazon S3, queue new file keys, and quit (maybe for Cron):
28
83
 
29
- It is necessary to choose a listener (IMAP|FTP) and a notifier (Sidekiq).
84
+ $ ryespy --listener amzn-s3 --amzn-s3-access-key c/example/com --amzn-s3-secret-key helpimabroccoli --amzn-s3-bucket vegetable-box --notifier-sidekiq
30
85
 
31
- Check IMAP and queue new emails and quit:
86
+ For non-* or multiple key prefix filters, use `--amzn-s3-prefixes virtual-dir1/,virtual-dir`.
32
87
 
33
- $ bundle exec ryespy --listener imap --imap-host mail.example.com --imap-username a@example.com --imap-password helpimacarrot --notifier-sidekiq
88
+ ### Google Cloud Storage Listener
34
89
 
35
- Check FTP and queue new files and quit:
90
+ Check Google Cloud Storage, queue new file keys, and quit (maybe for Cron):
36
91
 
37
- $ bundle exec ryespy --listener ftp --ftp-host ftp.example.com --ftp-username b@example.com --ftp-password helpimacucumber --notifier-sidekiq
92
+ $ ryespy --listener goog-cs --goog-cs-access-key d/example/com --goog-cs-secret-key helpimanasparagus --goog-cs-bucket vegetable-box --notifier-sidekiq
38
93
 
39
- IMAP SSL and FTP PASSIVE are also supported. It's also possible to watch more
40
- than one IMAP mailbox or FTP directory. The `--help` is most helpful.
94
+ For non-* or multiple key prefix filters, use `--goog-cs-prefixes virtual-dir1/,virtual-dir`.
41
95
 
42
- Use `--eternal` to run eternally.
96
+ ### Rackspace Cloud Files Listener
97
+
98
+ Check Rackspace Cloud Files, queue new file keys, and quit (maybe for Cron):
99
+
100
+ $ ryespy --listener rax-cf --rax-cf-username vegetable --rax-cf-api-key helpimacelery --rax-cf-container vegetable-box --notifier-sidekiq
101
+
102
+ For non-DFW region, use `--rax-cf-region lon`. For non-US auth endpoint, use `--rax-cf-endpoint uk`. Is your Rackspace account in London? Fret not; combine these and use `--rax-cf-endpoint uk --rax-cf-region lon`. For non-* or multiple key prefix filters, use `--rax-cf-prefixes virtual-dir1/,virtual-dir`.
103
+
104
+
105
+ ## Advanced Usage
106
+
107
+ If you want to do something rather more magical, such as checking multiple accounts for a listener or even multiple listeners, then you may wish to use the Ryespy library directly instead of the `ryespy` executable.
108
+
109
+ Depend upon the `ryespy` gem in a `Gemfile`, remembering to add any manual dependencies for listeners as detailed in [Installation](#installation):
110
+
111
+ # Gemfile
112
+
113
+ gem 'ryespy'
114
+ gem 'fog' # example manual dependency
115
+
116
+ Configure Ryespy Redis and require Ryespy:
117
+
118
+ require 'redis'
119
+ require 'redis/namespace'
120
+
121
+ Redis.current = Redis::Namespace.new('ryespy',
122
+ :redis => Redis.connect(:url => nil) # Redis default
123
+ )
124
+
125
+ require 'ryespy'
126
+
127
+ Create the notifiers:
128
+
129
+ require 'ryespy/notifier/sidekiq'
130
+
131
+ notifiers = []
132
+ notifiers << Ryespy::Notifier::Sidekiq.new(
133
+ :url => nil, # Redis default
134
+ :namespace => 'resque'
135
+ )
136
+
137
+ For each listener, configure like in `ryespy --help` but without the listener prefix and with `-` changed to `_` (e.g. `--amzn-s3-access-key` => `:access_key`). Pass in an array of notifiers. Note that the `check()` argument varies per listener, meaning IMAP mailbox, FTP directory, or storage key prefix.
138
+
139
+ require 'ryespy/listener/amzn_s3'
140
+
141
+ Ryespy::Listener::AmznS3.new(
142
+ :access_key => 'ACCESS_KEY',
143
+ :secret_key => 'SECRET_KEY',
144
+ :bucket => 'BUCKET',
145
+ :notifiers => notifiers
146
+ ) do |listener|
147
+ listener.check('prefix/')
148
+ end
149
+
150
+ That's about the size of it.
151
+
152
+
153
+ ## Stay Tuned
154
+
155
+ We have a [Librelist](http://librelist.com) mailing list!
156
+ To subscribe, send an email to <ryespy@librelist.com>.
157
+ To unsubscribe, send an email to <ryespy-unsubscribe@librelist.com>.
158
+ There be [archives](http://librelist.com/browser/ryespy/).
159
+ That was easy.
160
+
161
+ You can also become a [watcher](https://github.com/tiredpixel/ryespy/watchers)
162
+ on GitHub. And don't forget you can become a [stargazer](https://github.com/tiredpixel/ryespy/stargazers) if you are so minded. :D
43
163
 
44
164
 
45
165
  ## Growing Like Flowers
46
166
 
47
- Coming soon is a grand refactor sprinkled with lots of testing, ensuring that
48
- present code is stable. Then, something or other else. Like a URL notifier.
49
- Or maybe more listeners. Stay tuned -- or better still, help with the tuning.
167
+ Dear Me, Here is a vague wishlist:
168
+
169
+ - Additional notifiers (e.g. URL ?)
170
+
171
+ Also take a look at the [issue tracker](https://github.com/tiredpixel/ryespy/issues).
50
172
 
51
173
 
52
174
  ## Contributions
53
175
 
54
- Contributions are embraced with much love and affection! Please fork the
55
- repository and wizard your magic, ensuring that any tests are not broken by the
56
- changes. Then send a pull request. Simples! If you'd like to discuss what you're
57
- doing or planning to do, or if you get stuck on something, then just wave. :)
176
+ Contributions are embraced with much love and affection!
177
+ Please fork the repository and wizard your magic, preferably with plenty of
178
+ fairy-dust sprinkled over the tests. ;)
179
+ Then send me a pull request. Simples!
180
+ If you'd like to discuss what you're doing or planning to do, or if you get
181
+ stuck on something, then just wave. :)
58
182
 
59
183
  Do whatever makes you happy. We'll probably still like you. :)
60
184
 
61
- Tests are written using [minitest](https://github.com/seattlerb/minitest), which
62
- is included by default in Ruby 1.9 onwards. To run all tests:
185
+ Tests are written using [minitest](https://github.com/seattlerb/minitest),
186
+ which is included by default in Ruby 1.9 onwards. To run all tests:
63
187
 
64
188
  rake test
65
189
 
66
- Or, if you're of that turn of mind, use [TURN](https://github.com/TwP/turn)
67
- (`gem install turn`):
68
-
69
- turn test/
190
+ When using the `ryespy` executable in development, you'll probably want to set `--debug` mode so debug-level messages are logged and stack traces raised.
70
191
 
71
192
 
72
193
  ## Blessing
@@ -76,6 +197,6 @@ May you find peace, and help others to do likewise.
76
197
 
77
198
  ## Licence
78
199
 
79
- © [tiredpixel](http://www.tiredpixel.com) 2013. It is free software, released
80
- under the MIT License, and may be redistributed under the terms specified in
81
- `LICENSE`.
200
+ © [tiredpixel](http://www.tiredpixel.com) 2013.
201
+ It is free software, released under the MIT License, and may be redistributed
202
+ under the terms specified in `LICENSE`.
data/bin/ryespy CHANGED
@@ -4,125 +4,208 @@ $stdout.sync = true
4
4
 
5
5
  require 'optparse'
6
6
  require 'ostruct'
7
+ require 'logger'
7
8
 
8
9
  require File.expand_path(File.dirname(__FILE__) + '/../lib/ryespy')
9
10
 
10
11
 
11
12
  # = Parse opts
12
13
 
13
- options = OpenStruct.new
14
-
15
- options.notifiers = {
16
- :sidekiq => [],
17
- }
14
+ options = OpenStruct.new(
15
+ :notifiers => {}
16
+ )
18
17
 
19
18
  OptionParser.new do |opts|
20
- opts.banner = "Usage: ryespy [options]"
19
+ opts.version = "v#{Ryespy::VERSION}"
20
+
21
+ opts.banner = opts.ver
22
+
23
+ opts.separator ""
24
+ opts.separator "Usage: ryespy [OPTIONS]"
21
25
 
22
26
  opts.separator ""
23
27
  opts.separator "Listener:"
24
28
 
25
- opts.on("-l", "--listener LISTENER", [:imap, :ftp], "Listener (imap|ftp)") do |o|
26
- options[:listener] = o
29
+ opts.on("-l", "--listener LISTENER", [
30
+ 'imap',
31
+ 'ftp',
32
+ 'amzn-s3',
33
+ 'goog-cs',
34
+ 'rax-cf',
35
+ ], "Listener (imap|ftp|amzn-s3|goog-cs|rax-cf)") do |o|
36
+ options[:listener] = o.tr('-', '_').to_sym
27
37
  end
28
38
 
29
39
  opts.separator ""
30
40
  opts.separator "Polling:"
31
41
 
32
- opts.on("-e", "--[no-]eternal", "Run eternally") do |o|
42
+ opts.on("-e", "--[no-]eternal", "Run eternally (default: no)") do |o|
33
43
  options[:eternal] = o
34
44
  end
35
45
 
36
- opts.on("--polling-interval [N]", Integer, "Poll every N seconds when --eternal") do |o|
46
+ opts.on("--polling-interval [N]", Integer, "Poll every N seconds (default: 60)") do |o|
37
47
  options[:polling_interval] = o
38
48
  end
39
49
 
40
50
  opts.separator ""
41
51
  opts.separator "Redis:"
42
52
 
43
- opts.on("--redis-url [URL]", "Connect Redis to URL") do |o|
53
+ opts.on("--redis-url [URL]", "Ryespy URL (default: Redis default)") do |o|
44
54
  options[:redis_url] = o
45
55
  end
46
56
 
47
- opts.on("--redis-ns-ryespy [NS]", "Namespace Redis 'ryespy:' as NS") do |o|
57
+ opts.on("--redis-ns-ryespy [NS]", "Ryespy namespace (default: ryespy)") do |o|
48
58
  options[:redis_ns_ryespy] = o
49
59
  end
50
60
 
51
- opts.on("--redis-ns-notifiers [NS]", "Namespace notifiers Redis 'resque:' as NS") do |o|
52
- options[:redis_ns_notifiers] = o
53
- end
54
-
55
61
  opts.separator ""
56
- opts.separator "Listener imap:"
62
+ opts.separator "--listener imap (IMAP) :"
57
63
 
58
- opts.on("--imap-host HOST", "Connect IMAP with HOST") do |o|
64
+ opts.on("--imap-host HOST", "Server HOST") do |o|
59
65
  options[:imap_host] = o
60
66
  end
61
67
 
62
- opts.on("--imap-port [PORT]", Integer, "Connect IMAP with PORT") do |o|
68
+ opts.on("--imap-port [PORT]", Integer, "Server PORT (default: 993)") do |o|
63
69
  options[:imap_port] = o
64
70
  end
65
71
 
66
- opts.on("--[no-]imap-ssl", "Connect IMAP using SSL") do |o|
72
+ opts.on("--[no-]imap-ssl", "Use SSL (default: yes)") do |o|
67
73
  options[:imap_ssl] = o
68
74
  end
69
75
 
70
- opts.on("--imap-username USERNAME", "Connect IMAP with USERNAME") do |o|
76
+ opts.on("--imap-username USERNAME", "Auth USERNAME") do |o|
71
77
  options[:imap_username] = o
72
78
  end
73
79
 
74
- opts.on("--imap-password PASSWORD", "Connect IMAP with PASSWORD") do |o|
80
+ opts.on("--imap-password PASSWORD", "Auth PASSWORD") do |o|
75
81
  options[:imap_password] = o
76
82
  end
77
83
 
78
- opts.on("--imap-mailboxes [INBOX,DEV]", Array, "Read IMAP MAILBOXES") do |o|
79
- options[:imap_mailboxes] = o
84
+ opts.on("--imap-mailboxes [INBOX,Mu]", Array, "Mailboxes INBOX,Mu (default: INBOX)") do |o|
85
+ options[:imap_filters] = o
80
86
  end
81
87
 
82
88
  opts.separator ""
83
- opts.separator "Listener ftp:"
89
+ opts.separator "--listener ftp (FTP) :"
84
90
 
85
- opts.on("--ftp-host HOST", "Connect FTP with HOST") do |o|
91
+ opts.on("--ftp-host HOST", "Server HOST") do |o|
86
92
  options[:ftp_host] = o
87
93
  end
88
94
 
89
- opts.on("--[no-]ftp-passive", "Connect FTP using PASSIVE mode") do |o|
95
+ opts.on("--ftp-port [PORT]", Integer, "Server PORT (default: 21)") do |o|
96
+ options[:ftp_port] = o
97
+ end
98
+
99
+ opts.on("--[no-]ftp-passive", "Use PASSIVE mode (default: no)") do |o|
90
100
  options[:ftp_passive] = o
91
101
  end
92
102
 
93
- opts.on("--ftp-username USERNAME", "Connect FTP with USERNAME") do |o|
103
+ opts.on("--ftp-username USERNAME", "Auth USERNAME") do |o|
94
104
  options[:ftp_username] = o
95
105
  end
96
106
 
97
- opts.on("--ftp-password PASSWORD", "Connect FTP with PASSWORD") do |o|
107
+ opts.on("--ftp-password PASSWORD", "Auth PASSWORD") do |o|
98
108
  options[:ftp_password] = o
99
109
  end
100
110
 
101
- opts.on("--ftp-dirs [dir1,dir2]", Array, "Read FTP DIRS") do |o|
102
- options[:ftp_dirs] = o
111
+ opts.on("--ftp-dirs [/D1,/D2]", Array, "Directories /D1,/D2 (default: /)") do |o|
112
+ options[:ftp_filters] = o
113
+ end
114
+
115
+ opts.separator ""
116
+ opts.separator "--listener amzn-s3 (Amazon S3) :"
117
+
118
+ opts.on("--amzn-s3-access-key ACCESS", "Account ACCESS key") do |o|
119
+ options[:amzn_s3_access_key] = o
120
+ end
121
+
122
+ opts.on("--amzn-s3-secret-key SECRET", "Account SECRET key") do |o|
123
+ options[:amzn_s3_secret_key] = o
124
+ end
125
+
126
+ opts.on("--amzn-s3-bucket BUCKET", "Storage BUCKET") do |o|
127
+ options[:amzn_s3_bucket] = o
128
+ end
129
+
130
+ opts.on("--amzn-s3-prefixes [P1,P2]", Array, "Prefixes P1,P2 (default: *)") do |o|
131
+ options[:amzn_s3_filters] = o
132
+ end
133
+
134
+ opts.separator ""
135
+ opts.separator "--listener goog-cs (Google Cloud Storage) :"
136
+
137
+ opts.on("--goog-cs-access-key ACCESS", "Account ACCESS key") do |o|
138
+ options[:goog_cs_access_key] = o
139
+ end
140
+
141
+ opts.on("--goog-cs-secret-key SECRET", "Account SECRET key") do |o|
142
+ options[:goog_cs_secret_key] = o
143
+ end
144
+
145
+ opts.on("--goog-cs-bucket BUCKET", "Storage BUCKET") do |o|
146
+ options[:goog_cs_bucket] = o
147
+ end
148
+
149
+ opts.on("--goog-cs-prefixes [P1,P2]", Array, "Prefixes P1,P2 (default: *)") do |o|
150
+ options[:goog_cs_filters] = o
151
+ end
152
+
153
+ opts.separator ""
154
+ opts.separator "--listener rax-cf (Rackspace Cloud Files) :"
155
+
156
+ opts.on("--rax-cf-endpoint [ENDPOINT]", "Auth ENDPOINT (default: us)") do |o|
157
+ options[:rax_cf_endpoint] = o
158
+ end
159
+
160
+ opts.on("--rax-cf-username USERNAME", "Account USERNAME") do |o|
161
+ options[:rax_cf_username] = o
162
+ end
163
+
164
+ opts.on("--rax-cf-api-key API_KEY", "Account API_KEY") do |o|
165
+ options[:rax_cf_api_key] = o
166
+ end
167
+
168
+ opts.on("--rax-cf-container CONTAINER", "Storage CONTAINER") do |o|
169
+ options[:rax_cf_container] = o
170
+ end
171
+
172
+ opts.on("--rax-cf-region [REGION]", "Storage REGION (default: dfw)") do |o|
173
+ options[:rax_cf_region] = o
174
+ end
175
+
176
+ opts.on("--rax-cf-prefixes [P1,P2]", Array, "Prefixes P1,P2 (default: *)") do |o|
177
+ options[:rax_cf_filters] = o
103
178
  end
104
179
 
105
180
  opts.separator ""
106
- opts.separator "Notifier sidekiq:"
181
+ opts.separator "Notifiers:"
182
+
183
+ opts.on("--redis-ns-notifiers [NS]", "Notifiers namespace (default: resque)") do |o|
184
+ options[:redis_ns_notifiers] = o
185
+ end
107
186
 
108
- opts.on("--notifier-sidekiq [URL]", "Notify Sidekiq/Resque at Redis URL") do |o|
109
- options.notifiers[:sidekiq] << o
187
+ opts.on("--notifier-sidekiq [URL]", "Sidekiq Redis URL (default: Redis default)") do |o|
188
+ (options.notifiers[:sidekiq] ||= []) << o
110
189
  end
111
190
 
112
191
  opts.separator ""
113
192
  opts.separator "Other:"
114
193
 
115
- opts.on("-v", "--[no-]verbose", "Be somewhat verbose") do |o|
116
- options[:verbose] = o
194
+ opts.on("-d", "--debug", "Set debug mode") do |o|
195
+ options[:debug] = o
117
196
  end
118
197
 
119
- opts.on_tail("--help", "Show this message") do
198
+ opts.on_tail("--help",
199
+ "Output (this) help and exit"
200
+ ) do
120
201
  puts opts
121
202
  exit
122
203
  end
123
204
 
124
- opts.on_tail("--version", "Show version") do
125
- puts "Ryespy version:#{Ryespy::VERSION}"
205
+ opts.on_tail("--version",
206
+ "Output version and exit"
207
+ ) do
208
+ puts opts.ver
126
209
  exit
127
210
  end
128
211
  end.parse!
@@ -136,62 +219,85 @@ end.parse!
136
219
  end
137
220
 
138
221
 
222
+ # = Create app
223
+
224
+ @app = Ryespy::App.new(options[:eternal],
225
+ :logger => Logger.new($stdout)
226
+ )
227
+
228
+
139
229
  # = Configure
140
230
 
141
- Ryespy.configure do |c|
142
- c.log_level = 'DEBUG' if options[:verbose]
231
+ @app.configure do |c|
232
+ c.log_level = :DEBUG if options[:debug]
143
233
 
144
234
  c.listener = options[:listener]
145
235
 
146
- params = [
236
+ [
147
237
  :polling_interval,
148
238
  :redis_url,
149
239
  :redis_ns_ryespy,
150
240
  :redis_ns_notifiers,
151
241
  :notifiers,
152
- ]
153
-
154
- params.concat case c.listener.to_s
155
- when 'imap'
156
- [
157
- :imap_host,
158
- :imap_port,
159
- :imap_ssl,
160
- :imap_username,
161
- :imap_password,
162
- :imap_mailboxes,
163
- ]
164
- when 'ftp'
165
- [
166
- :ftp_host,
167
- :ftp_passive,
168
- :ftp_username,
169
- :ftp_password,
170
- :ftp_dirs,
171
- ]
172
- else
173
- []
242
+ ].each { |k| c[k] = options[k] unless options[k].nil? }
243
+
244
+ {
245
+ :imap => [
246
+ :host,
247
+ :port,
248
+ :ssl,
249
+ :username,
250
+ :password,
251
+ :filters, # mailboxes
252
+ ],
253
+ :ftp => [
254
+ :host,
255
+ :port,
256
+ :passive,
257
+ :username,
258
+ :password,
259
+ :filters, # dirs
260
+ ],
261
+ :amzn_s3 => [
262
+ :access_key,
263
+ :secret_key,
264
+ :bucket,
265
+ :filters, # prefixes
266
+ ],
267
+ :goog_cs => [
268
+ :access_key,
269
+ :secret_key,
270
+ :bucket,
271
+ :filters, # prefixes
272
+ ],
273
+ :rax_cf => [
274
+ :endpoint,
275
+ :region,
276
+ :username,
277
+ :api_key,
278
+ :container,
279
+ :filters, # prefixes
280
+ ],
281
+ }[c.listener].each do |k|
282
+ lk = "#{c.listener}_#{k}".to_sym
283
+
284
+ c[c.listener][k] = options[lk] unless options[lk].nil?
174
285
  end
175
-
176
- params.each { |s| c.send("#{s}=", options[s]) unless options[s].nil? }
177
286
  end
178
287
 
179
- @logger = Ryespy.logger
180
288
 
289
+ # = Run app
181
290
 
182
- # = Main loop
291
+ trap('INT') { @app.stop }
183
292
 
184
- loop do
185
- listener = {
186
- 'imap' => Ryespy::Listener::IMAP,
187
- 'ftp' => Ryespy::Listener::FTP,
188
- }[Ryespy.config.listener.to_s].new
189
-
190
- listener.check_all
191
-
192
- break unless options[:eternal]
293
+ begin
294
+ @app.start
295
+ rescue => e
296
+ warn "#{$0}: #{e}"
193
297
 
194
- @logger.debug { "Snoring for #{Ryespy.config.polling_interval} s" }
195
-
196
- sleep Ryespy.config.polling_interval # sleep awhile (snore)
298
+ if options[:debug]
299
+ raise # reraise for stacktrace
300
+ else
301
+ exit 1 # same non-zero status as when --debug
302
+ end
197
303
  end