ryespy 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +0,0 @@
1
- require 'json'
2
- require 'securerandom'
3
-
4
- require_relative '../redis_conn'
5
-
6
-
7
- module Ryespy
8
- module Notifier
9
- class Sidekiq
10
-
11
- RESQUE_QUEUE = 'ryespy'
12
-
13
- def initialize(url = nil)
14
- begin
15
- @redis_conn = Ryespy::RedisConn.new(url)
16
- rescue Errno::ECONNREFUSED, Net::FTPError => e
17
- Ryespy.logger.error { e.to_s }
18
-
19
- return
20
- end
21
-
22
- if block_given?
23
- yield self
24
-
25
- close
26
- end
27
- end
28
-
29
- def close
30
- @redis_conn.close
31
- end
32
-
33
- def notify(job_class, args)
34
- @redis_conn.redis.sadd("#{Ryespy.config.redis_ns_notifiers}queues", RESQUE_QUEUE)
35
-
36
- @redis_conn.redis.rpush("#{Ryespy.config.redis_ns_notifiers}queue:#{RESQUE_QUEUE}", {
37
- # resque
38
- :class => job_class,
39
- :args => args,
40
- # sidekiq (extra)
41
- :queue => RESQUE_QUEUE,
42
- :retry => true,
43
- :jid => SecureRandom.hex(12),
44
- }.to_json)
45
- end
46
-
47
- end
48
- end
49
- end
@@ -1,32 +0,0 @@
1
- require 'redis'
2
-
3
-
4
- module Ryespy
5
- class RedisConn
6
-
7
- attr_accessor :redis
8
-
9
- def initialize(url = nil)
10
- begin
11
- @redis = Redis.connect(:url => url)
12
-
13
- @redis.ping
14
- rescue Redis::CannotConnectError => e
15
- Ryespy.logger.error { e.to_s }
16
-
17
- return
18
- end
19
-
20
- if block_given?
21
- yield @redis
22
-
23
- close
24
- end
25
- end
26
-
27
- def close
28
- @redis.quit
29
- end
30
-
31
- end
32
- end
@@ -1,223 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require_relative '../../lib/ryespy'
4
- require_relative '../../lib/ryespy/config'
5
-
6
-
7
- describe Ryespy::Config do
8
-
9
- describe "default" do
10
- before do
11
- @config = Ryespy::Config.new
12
- end
13
-
14
- it "sets log_level to INFO" do
15
- @config.log_level.must_equal 'INFO'
16
- end
17
-
18
- it "sets polling_interval to 60" do
19
- @config.polling_interval.must_equal 60
20
- end
21
-
22
- it "sets redis_ns_ryespy to ryespy:" do
23
- @config.redis_ns_ryespy.must_equal 'ryespy:'
24
- end
25
-
26
- it "sets redis_ns_notifiers to resque:" do
27
- @config.redis_ns_notifiers.must_equal 'resque:'
28
- end
29
-
30
- it "sets notifiers hash structure" do
31
- @config.notifiers.must_equal({ :sidekiq => [] })
32
- end
33
-
34
- it "sets imap_port to 993" do
35
- @config.imap_port.must_equal 993
36
- end
37
-
38
- it "sets imap_ssl to true" do
39
- @config.imap_ssl.must_equal true
40
- end
41
-
42
- it "sets imap_mailboxes to INBOX" do
43
- @config.imap_mailboxes.must_equal ['INBOX']
44
- end
45
-
46
- it "sets ftp_passive to false" do
47
- @config.ftp_passive.must_equal false
48
- end
49
-
50
- it "sets ftp_dirs to /" do
51
- @config.ftp_dirs.must_equal ['/']
52
- end
53
- end
54
-
55
- describe "configure block main" do
56
- before do
57
- Ryespy.configure do |c|
58
- c.log_level = 'ERROR'
59
- c.listener = 'imap'
60
- c.polling_interval = 13
61
- c.redis_url = 'redis://127.0.0.1:6379/1'
62
- c.redis_ns_ryespy = 'WithMyLittleEye!'
63
- c.redis_ns_notifiers = 'LaLaLiLi-'
64
- c.notifiers = [{ :sidekiq => 'redis://127.0.0.1:6379/2' }]
65
- end
66
-
67
- @config = Ryespy.config
68
- end
69
-
70
- it "configures log_level" do
71
- @config.log_level.must_equal 'ERROR'
72
- end
73
-
74
- it "configures listener" do
75
- @config.listener.must_equal 'imap'
76
- end
77
-
78
- it "configures polling_interval" do
79
- @config.polling_interval.must_equal 13
80
- end
81
-
82
- it "configures redis_url" do
83
- @config.redis_url.must_equal 'redis://127.0.0.1:6379/1'
84
- end
85
-
86
- it "configures redis_ns_ryespy" do
87
- @config.redis_ns_ryespy.must_equal 'WithMyLittleEye!'
88
- end
89
-
90
- it "configures redis_ns_notifiers" do
91
- @config.redis_ns_notifiers.must_equal 'LaLaLiLi-'
92
- end
93
-
94
- it "configures notifiers" do
95
- @config.notifiers.must_equal [{ :sidekiq => 'redis://127.0.0.1:6379/2' }]
96
- end
97
- end
98
-
99
- describe "configure block listener IMAP" do
100
- before do
101
- Ryespy.configure do |c|
102
- c.imap_host = 'imap.example.com'
103
- c.imap_port = 143
104
- c.imap_ssl = false
105
- c.imap_username = 'lucy.westenra@example.com'
106
- c.imap_password = 'white'
107
- c.imap_mailboxes = 'BoxA,Sent Messages'
108
-
109
- @config = Ryespy.config
110
- end
111
- end
112
-
113
- it "configures imap_host" do
114
- @config.imap_host.must_equal 'imap.example.com'
115
- end
116
-
117
- it "configures imap_port" do
118
- @config.imap_port.must_equal 143
119
- end
120
-
121
- it "configures imap_ssl" do
122
- @config.imap_ssl.must_equal false
123
- end
124
-
125
- it "configures imap_username" do
126
- @config.imap_username.must_equal 'lucy.westenra@example.com'
127
- end
128
-
129
- it "configures imap_password" do
130
- @config.imap_password.must_equal 'white'
131
- end
132
-
133
- it "configures imap_mailboxes" do
134
- @config.imap_mailboxes.must_equal 'BoxA,Sent Messages'
135
- end
136
- end
137
-
138
- describe "configure block listener FTP" do
139
- before do
140
- Ryespy.configure do |c|
141
- c.ftp_host = 'ftp.example.org'
142
- c.ftp_passive = true
143
- c.ftp_username = 'madam.mina@example.com'
144
- c.ftp_password = 'black'
145
- c.ftp_dirs = ['BoxA', 'Sent Messages']
146
-
147
- @config = Ryespy.config
148
- end
149
- end
150
-
151
- it "configures ftp_host" do
152
- @config.ftp_host.must_equal 'ftp.example.org'
153
- end
154
-
155
- it "configures ftp_passive" do
156
- @config.ftp_passive.must_equal true
157
- end
158
-
159
- it "configures ftp_username" do
160
- @config.ftp_username.must_equal 'madam.mina@example.com'
161
- end
162
-
163
- it "configures ftp_password" do
164
- @config.ftp_password.must_equal 'black'
165
- end
166
-
167
- it "configures ftp_dirs" do
168
- @config.ftp_dirs.must_equal ['BoxA', 'Sent Messages']
169
- end
170
- end
171
-
172
- describe "#to_s" do
173
- before do
174
- @config = Ryespy::Config.new
175
- end
176
-
177
- describe "when listener NULL" do
178
- before do
179
- @config.listener = nil
180
- end
181
-
182
- it "stringifies hash of config" do
183
- @config.to_s.must_equal '{:log_level=>"INFO", :listener=>nil, :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}}'
184
- end
185
- end
186
-
187
- describe "when listener IMAP" do
188
- before do
189
- @config.listener = 'imap'
190
- end
191
-
192
- it "stringifies hash of config" do
193
- @config.to_s.must_equal '{:log_level=>"INFO", :listener=>"imap", :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}, :imap_host=>nil, :imap_port=>993, :imap_ssl=>true, :imap_username=>nil, :imap_password=>nil}'
194
- end
195
- end
196
-
197
- describe "when listener FTP" do
198
- before do
199
- @config.listener = 'ftp'
200
- end
201
-
202
- it "stringifies hash of config" do
203
- @config.to_s.must_equal '{:log_level=>"INFO", :listener=>"ftp", :polling_interval=>60, :redis_url=>nil, :redis_ns_ryespy=>"ryespy:", :redis_ns_notifiers=>"resque:", :notifiers=>{:sidekiq=>[]}, :ftp_host=>nil, :ftp_passive=>false, :ftp_username=>nil, :ftp_dirs=>["/"]}'
204
- end
205
- end
206
- end
207
-
208
- describe "#redis_prefix_ryespy" do
209
- before do
210
- Ryespy.configure do |c|
211
- c.listener = 'earear'
212
- c.redis_ns_ryespy = 'LittleEye:'
213
- end
214
-
215
- @config = Ryespy.config
216
- end
217
-
218
- it "returns key prefix" do
219
- @config.redis_prefix_ryespy.must_equal "LittleEye:earear:"
220
- end
221
- end
222
-
223
- end
File without changes