sidekiq 3.4.1 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (235) hide show
  1. checksums.yaml +5 -5
  2. data/Changes.md +1118 -4
  3. data/LICENSE.txt +9 -0
  4. data/README.md +55 -47
  5. data/bin/multi_queue_bench +271 -0
  6. data/bin/sidekiq +26 -3
  7. data/bin/sidekiqload +247 -0
  8. data/bin/sidekiqmon +11 -0
  9. data/lib/generators/sidekiq/job_generator.rb +57 -0
  10. data/lib/generators/sidekiq/templates/{worker.rb.erb → job.rb.erb} +2 -2
  11. data/lib/generators/sidekiq/templates/job_spec.rb.erb +6 -0
  12. data/lib/generators/sidekiq/templates/job_test.rb.erb +8 -0
  13. data/lib/sidekiq/api.rb +714 -312
  14. data/lib/sidekiq/capsule.rb +130 -0
  15. data/lib/sidekiq/cli.rb +275 -241
  16. data/lib/sidekiq/client.rb +141 -110
  17. data/lib/sidekiq/component.rb +68 -0
  18. data/lib/sidekiq/config.rb +291 -0
  19. data/lib/sidekiq/deploy.rb +62 -0
  20. data/lib/sidekiq/embedded.rb +61 -0
  21. data/lib/sidekiq/fetch.rb +53 -121
  22. data/lib/sidekiq/iterable_job.rb +53 -0
  23. data/lib/sidekiq/job/interrupt_handler.rb +22 -0
  24. data/lib/sidekiq/job/iterable/active_record_enumerator.rb +53 -0
  25. data/lib/sidekiq/job/iterable/csv_enumerator.rb +47 -0
  26. data/lib/sidekiq/job/iterable/enumerators.rb +135 -0
  27. data/lib/sidekiq/job/iterable.rb +231 -0
  28. data/lib/sidekiq/job.rb +385 -0
  29. data/lib/sidekiq/job_logger.rb +64 -0
  30. data/lib/sidekiq/job_retry.rb +305 -0
  31. data/lib/sidekiq/job_util.rb +107 -0
  32. data/lib/sidekiq/launcher.rb +241 -66
  33. data/lib/sidekiq/logger.rb +131 -0
  34. data/lib/sidekiq/manager.rb +91 -192
  35. data/lib/sidekiq/metrics/query.rb +156 -0
  36. data/lib/sidekiq/metrics/shared.rb +95 -0
  37. data/lib/sidekiq/metrics/tracking.rb +140 -0
  38. data/lib/sidekiq/middleware/chain.rb +114 -56
  39. data/lib/sidekiq/middleware/current_attributes.rb +111 -0
  40. data/lib/sidekiq/middleware/i18n.rb +8 -7
  41. data/lib/sidekiq/middleware/modules.rb +21 -0
  42. data/lib/sidekiq/monitor.rb +146 -0
  43. data/lib/sidekiq/paginator.rb +29 -16
  44. data/lib/sidekiq/processor.rb +248 -112
  45. data/lib/sidekiq/rails.rb +61 -27
  46. data/lib/sidekiq/redis_client_adapter.rb +114 -0
  47. data/lib/sidekiq/redis_connection.rb +68 -48
  48. data/lib/sidekiq/ring_buffer.rb +29 -0
  49. data/lib/sidekiq/scheduled.rb +173 -52
  50. data/lib/sidekiq/sd_notify.rb +149 -0
  51. data/lib/sidekiq/systemd.rb +24 -0
  52. data/lib/sidekiq/testing/inline.rb +7 -5
  53. data/lib/sidekiq/testing.rb +206 -65
  54. data/lib/sidekiq/transaction_aware_client.rb +51 -0
  55. data/lib/sidekiq/version.rb +4 -1
  56. data/lib/sidekiq/web/action.rb +99 -0
  57. data/lib/sidekiq/web/application.rb +479 -0
  58. data/lib/sidekiq/web/csrf_protection.rb +183 -0
  59. data/lib/sidekiq/web/helpers.rb +415 -0
  60. data/lib/sidekiq/web/router.rb +104 -0
  61. data/lib/sidekiq/web.rb +158 -200
  62. data/lib/sidekiq/worker_compatibility_alias.rb +13 -0
  63. data/lib/sidekiq.rb +100 -132
  64. data/sidekiq.gemspec +27 -23
  65. data/web/assets/images/apple-touch-icon.png +0 -0
  66. data/web/assets/images/favicon.ico +0 -0
  67. data/web/assets/javascripts/application.js +177 -72
  68. data/web/assets/javascripts/base-charts.js +106 -0
  69. data/web/assets/javascripts/chart.min.js +13 -0
  70. data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
  71. data/web/assets/javascripts/dashboard-charts.js +192 -0
  72. data/web/assets/javascripts/dashboard.js +37 -286
  73. data/web/assets/javascripts/metrics.js +298 -0
  74. data/web/assets/stylesheets/application-dark.css +147 -0
  75. data/web/assets/stylesheets/application-rtl.css +163 -0
  76. data/web/assets/stylesheets/application.css +228 -247
  77. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  78. data/web/assets/stylesheets/bootstrap.css +4 -8
  79. data/web/locales/ar.yml +87 -0
  80. data/web/locales/cs.yml +62 -52
  81. data/web/locales/da.yml +60 -53
  82. data/web/locales/de.yml +65 -53
  83. data/web/locales/el.yml +43 -24
  84. data/web/locales/en.yml +86 -61
  85. data/web/locales/es.yml +70 -53
  86. data/web/locales/fa.yml +80 -0
  87. data/web/locales/fr.yml +86 -56
  88. data/web/locales/gd.yml +99 -0
  89. data/web/locales/he.yml +80 -0
  90. data/web/locales/hi.yml +59 -59
  91. data/web/locales/it.yml +53 -53
  92. data/web/locales/ja.yml +78 -56
  93. data/web/locales/ko.yml +52 -52
  94. data/web/locales/lt.yml +83 -0
  95. data/web/locales/{no.yml → nb.yml} +62 -54
  96. data/web/locales/nl.yml +52 -52
  97. data/web/locales/pl.yml +45 -45
  98. data/web/locales/pt-br.yml +83 -55
  99. data/web/locales/pt.yml +51 -51
  100. data/web/locales/ru.yml +68 -60
  101. data/web/locales/sv.yml +53 -53
  102. data/web/locales/ta.yml +60 -60
  103. data/web/locales/tr.yml +101 -0
  104. data/web/locales/uk.yml +77 -0
  105. data/web/locales/ur.yml +80 -0
  106. data/web/locales/vi.yml +83 -0
  107. data/web/locales/zh-cn.yml +43 -16
  108. data/web/locales/zh-tw.yml +42 -8
  109. data/web/views/_footer.erb +22 -9
  110. data/web/views/_job_info.erb +27 -6
  111. data/web/views/_metrics_period_select.erb +12 -0
  112. data/web/views/_nav.erb +8 -22
  113. data/web/views/_paging.erb +3 -1
  114. data/web/views/_poll_link.erb +4 -0
  115. data/web/views/_summary.erb +7 -7
  116. data/web/views/busy.erb +91 -31
  117. data/web/views/dashboard.erb +52 -22
  118. data/web/views/dead.erb +5 -4
  119. data/web/views/filtering.erb +7 -0
  120. data/web/views/layout.erb +19 -7
  121. data/web/views/metrics.erb +91 -0
  122. data/web/views/metrics_for_job.erb +59 -0
  123. data/web/views/morgue.erb +26 -20
  124. data/web/views/queue.erb +36 -25
  125. data/web/views/queues.erb +24 -7
  126. data/web/views/retries.erb +29 -21
  127. data/web/views/retry.erb +6 -5
  128. data/web/views/scheduled.erb +20 -17
  129. data/web/views/scheduled_job_info.erb +2 -1
  130. metadata +101 -232
  131. data/.gitignore +0 -12
  132. data/.travis.yml +0 -16
  133. data/3.0-Upgrade.md +0 -70
  134. data/COMM-LICENSE +0 -85
  135. data/Contributing.md +0 -32
  136. data/Gemfile +0 -22
  137. data/LICENSE +0 -9
  138. data/Pro-2.0-Upgrade.md +0 -138
  139. data/Pro-Changes.md +0 -412
  140. data/Rakefile +0 -9
  141. data/bin/sidekiqctl +0 -93
  142. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +0 -6
  143. data/lib/generators/sidekiq/templates/worker_test.rb.erb +0 -8
  144. data/lib/generators/sidekiq/worker_generator.rb +0 -49
  145. data/lib/sidekiq/actor.rb +0 -39
  146. data/lib/sidekiq/core_ext.rb +0 -105
  147. data/lib/sidekiq/exception_handler.rb +0 -30
  148. data/lib/sidekiq/extensions/action_mailer.rb +0 -56
  149. data/lib/sidekiq/extensions/active_record.rb +0 -39
  150. data/lib/sidekiq/extensions/class_methods.rb +0 -39
  151. data/lib/sidekiq/extensions/generic_proxy.rb +0 -24
  152. data/lib/sidekiq/logging.rb +0 -104
  153. data/lib/sidekiq/middleware/server/active_record.rb +0 -13
  154. data/lib/sidekiq/middleware/server/logging.rb +0 -35
  155. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -206
  156. data/lib/sidekiq/util.rb +0 -55
  157. data/lib/sidekiq/web_helpers.rb +0 -234
  158. data/lib/sidekiq/worker.rb +0 -89
  159. data/test/config.yml +0 -9
  160. data/test/env_based_config.yml +0 -11
  161. data/test/fake_env.rb +0 -0
  162. data/test/fixtures/en.yml +0 -2
  163. data/test/helper.rb +0 -39
  164. data/test/test_api.rb +0 -494
  165. data/test/test_cli.rb +0 -365
  166. data/test/test_client.rb +0 -269
  167. data/test/test_exception_handler.rb +0 -55
  168. data/test/test_extensions.rb +0 -120
  169. data/test/test_fetch.rb +0 -104
  170. data/test/test_logging.rb +0 -34
  171. data/test/test_manager.rb +0 -164
  172. data/test/test_middleware.rb +0 -159
  173. data/test/test_processor.rb +0 -166
  174. data/test/test_redis_connection.rb +0 -127
  175. data/test/test_retry.rb +0 -373
  176. data/test/test_scheduled.rb +0 -120
  177. data/test/test_scheduling.rb +0 -71
  178. data/test/test_sidekiq.rb +0 -69
  179. data/test/test_testing.rb +0 -82
  180. data/test/test_testing_fake.rb +0 -271
  181. data/test/test_testing_inline.rb +0 -93
  182. data/test/test_web.rb +0 -594
  183. data/test/test_web_helpers.rb +0 -52
  184. data/test/test_worker_generator.rb +0 -17
  185. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  186. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  187. data/web/assets/images/status/active.png +0 -0
  188. data/web/assets/images/status/idle.png +0 -0
  189. data/web/assets/javascripts/locales/README.md +0 -27
  190. data/web/assets/javascripts/locales/jquery.timeago.ar.js +0 -96
  191. data/web/assets/javascripts/locales/jquery.timeago.bg.js +0 -18
  192. data/web/assets/javascripts/locales/jquery.timeago.bs.js +0 -49
  193. data/web/assets/javascripts/locales/jquery.timeago.ca.js +0 -18
  194. data/web/assets/javascripts/locales/jquery.timeago.cs.js +0 -18
  195. data/web/assets/javascripts/locales/jquery.timeago.cy.js +0 -20
  196. data/web/assets/javascripts/locales/jquery.timeago.da.js +0 -18
  197. data/web/assets/javascripts/locales/jquery.timeago.de.js +0 -18
  198. data/web/assets/javascripts/locales/jquery.timeago.el.js +0 -18
  199. data/web/assets/javascripts/locales/jquery.timeago.en-short.js +0 -20
  200. data/web/assets/javascripts/locales/jquery.timeago.en.js +0 -20
  201. data/web/assets/javascripts/locales/jquery.timeago.es.js +0 -18
  202. data/web/assets/javascripts/locales/jquery.timeago.et.js +0 -18
  203. data/web/assets/javascripts/locales/jquery.timeago.fa.js +0 -22
  204. data/web/assets/javascripts/locales/jquery.timeago.fi.js +0 -28
  205. data/web/assets/javascripts/locales/jquery.timeago.fr-short.js +0 -16
  206. data/web/assets/javascripts/locales/jquery.timeago.fr.js +0 -17
  207. data/web/assets/javascripts/locales/jquery.timeago.he.js +0 -18
  208. data/web/assets/javascripts/locales/jquery.timeago.hr.js +0 -49
  209. data/web/assets/javascripts/locales/jquery.timeago.hu.js +0 -18
  210. data/web/assets/javascripts/locales/jquery.timeago.hy.js +0 -18
  211. data/web/assets/javascripts/locales/jquery.timeago.id.js +0 -18
  212. data/web/assets/javascripts/locales/jquery.timeago.it.js +0 -16
  213. data/web/assets/javascripts/locales/jquery.timeago.ja.js +0 -19
  214. data/web/assets/javascripts/locales/jquery.timeago.ko.js +0 -17
  215. data/web/assets/javascripts/locales/jquery.timeago.lt.js +0 -20
  216. data/web/assets/javascripts/locales/jquery.timeago.mk.js +0 -20
  217. data/web/assets/javascripts/locales/jquery.timeago.nl.js +0 -20
  218. data/web/assets/javascripts/locales/jquery.timeago.no.js +0 -18
  219. data/web/assets/javascripts/locales/jquery.timeago.pl.js +0 -31
  220. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +0 -16
  221. data/web/assets/javascripts/locales/jquery.timeago.pt.js +0 -16
  222. data/web/assets/javascripts/locales/jquery.timeago.ro.js +0 -18
  223. data/web/assets/javascripts/locales/jquery.timeago.rs.js +0 -49
  224. data/web/assets/javascripts/locales/jquery.timeago.ru.js +0 -34
  225. data/web/assets/javascripts/locales/jquery.timeago.sk.js +0 -18
  226. data/web/assets/javascripts/locales/jquery.timeago.sl.js +0 -44
  227. data/web/assets/javascripts/locales/jquery.timeago.sv.js +0 -18
  228. data/web/assets/javascripts/locales/jquery.timeago.th.js +0 -20
  229. data/web/assets/javascripts/locales/jquery.timeago.tr.js +0 -16
  230. data/web/assets/javascripts/locales/jquery.timeago.uk.js +0 -34
  231. data/web/assets/javascripts/locales/jquery.timeago.uz.js +0 -19
  232. data/web/assets/javascripts/locales/jquery.timeago.zh-cn.js +0 -20
  233. data/web/assets/javascripts/locales/jquery.timeago.zh-tw.js +0 -20
  234. data/web/views/_poll.erb +0 -10
  235. /data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
data/test/test_cli.rb DELETED
@@ -1,365 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/cli'
3
- require 'tempfile'
4
-
5
- class Sidekiq::CLI
6
- def die(code)
7
- @code = code
8
- end
9
-
10
- def valid?
11
- !@code
12
- end
13
- end
14
-
15
- class TestCli < Sidekiq::Test
16
- describe 'CLI#parse' do
17
-
18
- before do
19
- @cli = Sidekiq::CLI.new
20
- @opts = Sidekiq.options.dup
21
- end
22
-
23
- after do
24
- Sidekiq.options = @opts
25
- end
26
-
27
- it 'does not require the specified Ruby code' do
28
- @cli.parse(['sidekiq', '-r', './test/fake_env.rb'])
29
- refute($LOADED_FEATURES.any? { |x| x =~ /fake_env/ })
30
- assert @cli.valid?
31
- end
32
-
33
- it 'does not boot rails' do
34
- refute defined?(::Rails::Application)
35
- @cli.parse(['sidekiq', '-r', './myapp'])
36
- refute defined?(::Rails::Application)
37
- end
38
-
39
- it 'changes concurrency' do
40
- @cli.parse(['sidekiq', '-c', '60', '-r', './test/fake_env.rb'])
41
- assert_equal 60, Sidekiq.options[:concurrency]
42
- end
43
-
44
- it 'changes queues' do
45
- @cli.parse(['sidekiq', '-q', 'foo', '-r', './test/fake_env.rb'])
46
- assert_equal ['foo'], Sidekiq.options[:queues]
47
- end
48
-
49
- it 'accepts a process index' do
50
- @cli.parse(['sidekiq', '-i', '7', '-r', './test/fake_env.rb'])
51
- assert_equal 7, Sidekiq.options[:index]
52
- end
53
-
54
- it 'accepts a stringy process index' do
55
- @cli.parse(['sidekiq', '-i', 'worker.7', '-r', './test/fake_env.rb'])
56
- assert_equal 7, Sidekiq.options[:index]
57
- end
58
-
59
- it 'sets strictly ordered queues if weights are not present' do
60
- @cli.parse(['sidekiq', '-q', 'foo', '-q', 'bar', '-r', './test/fake_env.rb'])
61
- assert_equal true, !!Sidekiq.options[:strict]
62
- end
63
-
64
- it 'does not set strictly ordered queues if weights are present' do
65
- @cli.parse(['sidekiq', '-q', 'foo,3', '-r', './test/fake_env.rb'])
66
- assert_equal false, !!Sidekiq.options[:strict]
67
- end
68
-
69
- it 'does not set strictly ordered queues if weights are present with multiple queues' do
70
- @cli.parse(['sidekiq', '-q', 'foo,3', '-q', 'bar', '-r', './test/fake_env.rb'])
71
- assert_equal false, !!Sidekiq.options[:strict]
72
- end
73
-
74
- it 'changes timeout' do
75
- @cli.parse(['sidekiq', '-t', '30', '-r', './test/fake_env.rb'])
76
- assert_equal 30, Sidekiq.options[:timeout]
77
- end
78
-
79
- it 'handles multiple queues with weights' do
80
- @cli.parse(['sidekiq', '-q', 'foo,3', '-q', 'bar', '-r', './test/fake_env.rb'])
81
- assert_equal %w(foo foo foo bar), Sidekiq.options[:queues]
82
- end
83
-
84
- it 'handles queues with multi-word names' do
85
- @cli.parse(['sidekiq', '-q', 'queue_one', '-q', 'queue-two', '-r', './test/fake_env.rb'])
86
- assert_equal %w(queue_one queue-two), Sidekiq.options[:queues]
87
- end
88
-
89
- it 'handles queues with dots in the name' do
90
- @cli.parse(['sidekiq', '-q', 'foo.bar', '-r', './test/fake_env.rb'])
91
- assert_equal ['foo.bar'], Sidekiq.options[:queues]
92
- end
93
-
94
- it 'sets verbose' do
95
- old = Sidekiq.logger.level
96
- @cli.parse(['sidekiq', '-v', '-r', './test/fake_env.rb'])
97
- assert_equal Logger::DEBUG, Sidekiq.logger.level
98
- # If we leave the logger at DEBUG it'll add a lot of noise to the test output
99
- Sidekiq.options.delete(:verbose)
100
- Sidekiq.logger.level = old
101
- end
102
-
103
- describe 'with logfile' do
104
- before do
105
- @old_logger = Sidekiq.logger
106
- @tmp_log_path = '/tmp/sidekiq.log'
107
- end
108
-
109
- after do
110
- Sidekiq.logger = @old_logger
111
- Sidekiq.options.delete(:logfile)
112
- File.unlink @tmp_log_path if File.exist?(@tmp_log_path)
113
- end
114
-
115
- it 'sets the logfile path' do
116
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
117
-
118
- assert_equal @tmp_log_path, Sidekiq.options[:logfile]
119
- end
120
-
121
- it 'creates and writes to a logfile' do
122
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
123
-
124
- Sidekiq.logger.info('test message')
125
-
126
- assert_match(/test message/, File.read(@tmp_log_path), "didn't include the log message")
127
- end
128
-
129
- it 'appends messages to a logfile' do
130
- File.open(@tmp_log_path, 'w') do |f|
131
- f.puts 'already existant log message'
132
- end
133
-
134
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
135
-
136
- Sidekiq.logger.info('test message')
137
-
138
- log_file_content = File.read(@tmp_log_path)
139
- assert_match(/already existant/, log_file_content, "didn't include the old message")
140
- assert_match(/test message/, log_file_content, "didn't include the new message")
141
- end
142
- end
143
-
144
- describe 'with pidfile' do
145
- before do
146
- @tmp_file = Tempfile.new('sidekiq-test')
147
- @tmp_path = @tmp_file.path
148
- @tmp_file.close!
149
-
150
- @cli.parse(['sidekiq', '-P', @tmp_path, '-r', './test/fake_env.rb'])
151
- end
152
-
153
- after do
154
- File.unlink @tmp_path if File.exist? @tmp_path
155
- end
156
-
157
- it 'sets pidfile path' do
158
- assert_equal @tmp_path, Sidekiq.options[:pidfile]
159
- end
160
-
161
- it 'writes pidfile' do
162
- assert_equal File.read(@tmp_path).strip.to_i, Process.pid
163
- end
164
- end
165
-
166
- describe 'with config file' do
167
- before do
168
- @cli.parse(['sidekiq', '-C', './test/config.yml'])
169
- end
170
-
171
- it 'takes a path' do
172
- assert_equal './test/config.yml', Sidekiq.options[:config_file]
173
- end
174
-
175
- it 'sets verbose' do
176
- refute Sidekiq.options[:verbose]
177
- end
178
-
179
- it 'sets require file' do
180
- assert_equal './test/fake_env.rb', Sidekiq.options[:require]
181
- end
182
-
183
- it 'does not set environment' do
184
- assert_equal nil, Sidekiq.options[:environment]
185
- end
186
-
187
- it 'sets concurrency' do
188
- assert_equal 50, Sidekiq.options[:concurrency]
189
- end
190
-
191
- it 'sets pid file' do
192
- assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
193
- end
194
-
195
- it 'sets logfile' do
196
- assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
197
- end
198
-
199
- it 'sets queues' do
200
- assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
201
- assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
202
- end
203
- end
204
-
205
- describe 'with env based config file' do
206
- before do
207
- @cli.parse(['sidekiq', '-e', 'staging', '-C', './test/env_based_config.yml'])
208
- end
209
-
210
- it 'takes a path' do
211
- assert_equal './test/env_based_config.yml', Sidekiq.options[:config_file]
212
- end
213
-
214
- it 'sets verbose' do
215
- refute Sidekiq.options[:verbose]
216
- end
217
-
218
- it 'sets require file' do
219
- assert_equal './test/fake_env.rb', Sidekiq.options[:require]
220
- end
221
-
222
- it 'sets environment' do
223
- assert_equal 'staging', Sidekiq.options[:environment]
224
- end
225
-
226
- it 'sets concurrency' do
227
- assert_equal 5, Sidekiq.options[:concurrency]
228
- end
229
-
230
- it 'sets pid file' do
231
- assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
232
- end
233
-
234
- it 'sets logfile' do
235
- assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
236
- end
237
-
238
- it 'sets queues' do
239
- assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
240
- assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
241
- end
242
- end
243
-
244
- describe 'with an empty config file' do
245
- before do
246
- @tmp_file = Tempfile.new('sidekiq-test')
247
- @tmp_path = @tmp_file.path
248
- @tmp_file.close!
249
- end
250
-
251
- after do
252
- File.unlink @tmp_path if File.exist? @tmp_path
253
- end
254
-
255
- it 'takes a path' do
256
- @cli.parse(['sidekiq', '-C', @tmp_path])
257
- assert_equal @tmp_path, Sidekiq.options[:config_file]
258
- end
259
-
260
- it 'should have an identical options hash, except for config_file' do
261
- @cli.parse(['sidekiq'])
262
- old_options = Sidekiq.options.clone
263
-
264
- @cli.parse(['sidekiq', '-C', @tmp_path])
265
- new_options = Sidekiq.options.clone
266
- refute_equal old_options, new_options
267
-
268
- new_options.delete(:config_file)
269
- assert_equal old_options, new_options
270
- end
271
- end
272
-
273
- describe 'with config file and flags' do
274
- before do
275
- # We need an actual file here.
276
- @tmp_lib_path = '/tmp/require-me.rb'
277
- File.open(@tmp_lib_path, 'w') do |f|
278
- f.puts "# do work"
279
- end
280
-
281
- @tmp_file = Tempfile.new('sidekiqr')
282
- @tmp_path = @tmp_file.path
283
- @tmp_file.close!
284
-
285
- @cli.parse(['sidekiq',
286
- '-C', './test/config.yml',
287
- '-e', 'snoop',
288
- '-c', '100',
289
- '-r', @tmp_lib_path,
290
- '-P', @tmp_path,
291
- '-q', 'often,7',
292
- '-q', 'seldom,3'])
293
- end
294
-
295
- after do
296
- File.unlink @tmp_lib_path if File.exist? @tmp_lib_path
297
- File.unlink @tmp_path if File.exist? @tmp_path
298
- end
299
-
300
- it 'uses concurrency flag' do
301
- assert_equal 100, Sidekiq.options[:concurrency]
302
- end
303
-
304
- it 'uses require file flag' do
305
- assert_equal @tmp_lib_path, Sidekiq.options[:require]
306
- end
307
-
308
- it 'uses environment flag' do
309
- assert_equal 'snoop', Sidekiq.options[:environment]
310
- end
311
-
312
- it 'uses pidfile flag' do
313
- assert_equal @tmp_path, Sidekiq.options[:pidfile]
314
- end
315
-
316
- it 'sets queues' do
317
- assert_equal 7, Sidekiq.options[:queues].count { |q| q == 'often' }
318
- assert_equal 3, Sidekiq.options[:queues].count { |q| q == 'seldom' }
319
- end
320
- end
321
-
322
- describe 'Sidekiq::CLI#parse_queues' do
323
- describe 'when weight is present' do
324
- it 'concatenates queues by factor of weight and sets strict to false' do
325
- opts = { strict: true }
326
- @cli.__send__ :parse_queues, opts, [['often', 7], ['repeatedly', 3]]
327
- @cli.__send__ :parse_queues, opts, [['once']]
328
- assert_equal (%w[often] * 7 + %w[repeatedly] * 3 + %w[once]), opts[:queues]
329
- assert !opts[:strict]
330
- end
331
- end
332
-
333
- describe 'when weight is not present' do
334
- it 'returns queues and sets strict' do
335
- opts = { strict: true }
336
- @cli.__send__ :parse_queues, opts, [['once'], ['one_time']]
337
- @cli.__send__ :parse_queues, opts, [['einmal']]
338
- assert_equal %w[once one_time einmal], opts[:queues]
339
- assert opts[:strict]
340
- end
341
- end
342
- end
343
-
344
- describe 'Sidekiq::CLI#parse_queue' do
345
- describe 'when weight is present' do
346
- it 'concatenates queue to opts[:queues] weight number of times and sets strict to false' do
347
- opts = { strict: true }
348
- @cli.__send__ :parse_queue, opts, 'often', 7
349
- assert_equal %w[often] * 7, opts[:queues]
350
- assert !opts[:strict]
351
- end
352
- end
353
-
354
- describe 'when weight is not present' do
355
- it 'concatenates queue to opts[:queues] once and leaves strict true' do
356
- opts = { strict: true }
357
- @cli.__send__ :parse_queue, opts, 'once', nil
358
- assert_equal %w[once], opts[:queues]
359
- assert opts[:strict]
360
- end
361
- end
362
- end
363
- end
364
-
365
- end
data/test/test_client.rb DELETED
@@ -1,269 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/client'
3
- require 'sidekiq/worker'
4
-
5
- class TestClient < Sidekiq::Test
6
- describe 'with mock redis' do
7
- before do
8
- @redis = Minitest::Mock.new
9
- def @redis.multi; [yield] * 2 if block_given?; end
10
- def @redis.set(*); true; end
11
- def @redis.sadd(*); true; end
12
- def @redis.srem(*); true; end
13
- def @redis.get(*); nil; end
14
- def @redis.del(*); nil; end
15
- def @redis.incrby(*); nil; end
16
- def @redis.setex(*); true; end
17
- def @redis.expire(*); true; end
18
- def @redis.watch(*); true; end
19
- def @redis.with_connection; yield self; end
20
- def @redis.with; yield self; end
21
- def @redis.exec; true; end
22
- Sidekiq.instance_variable_set(:@redis, @redis)
23
- Sidekiq::Client.instance_variable_set(:@default, nil)
24
- end
25
-
26
- after do
27
- Sidekiq.redis = REDIS
28
- Sidekiq::Client.instance_variable_set(:@default, nil)
29
- end
30
-
31
- it 'raises ArgumentError with invalid params' do
32
- assert_raises ArgumentError do
33
- Sidekiq::Client.push('foo', 1)
34
- end
35
-
36
- assert_raises ArgumentError do
37
- Sidekiq::Client.push('foo', :class => 'Foo', :noargs => [1, 2])
38
- end
39
-
40
- assert_raises ArgumentError do
41
- Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'noargs' => [1, 2])
42
- end
43
-
44
- assert_raises ArgumentError do
45
- Sidekiq::Client.push('queue' => 'foo', 'class' => 42, 'args' => [1, 2])
46
- end
47
-
48
- assert_raises ArgumentError do
49
- Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => 1)
50
- end
51
- end
52
-
53
- describe 'as instance' do
54
- it 'can push' do
55
- @redis.expect :lpush, 1, ['queue:default', Array]
56
- client = Sidekiq::Client.new
57
- jid = client.push('class' => 'Blah', 'args' => [1,2,3])
58
- assert_equal 24, jid.size
59
- end
60
-
61
- it 'allows local middleware modification' do
62
- @redis.expect :lpush, 1, ['queue:default', Array]
63
- $called = false
64
- mware = Class.new { def call(worker_klass,msg,q,r); $called = true; msg;end }
65
- client = Sidekiq::Client.new
66
- client.middleware do |chain|
67
- chain.add mware
68
- end
69
- client.push('class' => 'Blah', 'args' => [1,2,3])
70
-
71
- assert $called
72
- assert client.middleware.exists?(mware)
73
- refute Sidekiq.client_middleware.exists?(mware)
74
- end
75
- end
76
-
77
- it 'pushes messages to redis' do
78
- @redis.expect :lpush, 1, ['queue:foo', Array]
79
- pushed = Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => [1, 2])
80
- assert pushed
81
- assert_equal 24, pushed.size
82
- @redis.verify
83
- end
84
-
85
- it 'pushes messages to redis using a String class' do
86
- @redis.expect :lpush, 1, ['queue:foo', Array]
87
- pushed = Sidekiq::Client.push('queue' => 'foo', 'class' => 'MyWorker', 'args' => [1, 2])
88
- assert pushed
89
- assert_equal 24, pushed.size
90
- @redis.verify
91
- end
92
-
93
- class MyWorker
94
- include Sidekiq::Worker
95
- end
96
-
97
- it 'has default options' do
98
- assert_equal Sidekiq.default_worker_options, MyWorker.get_sidekiq_options
99
- end
100
-
101
- it 'handles perform_async' do
102
- @redis.expect :lpush, 1, ['queue:default', Array]
103
- pushed = MyWorker.perform_async(1, 2)
104
- assert pushed
105
- @redis.verify
106
- end
107
-
108
- it 'enqueues messages to redis' do
109
- @redis.expect :lpush, 1, ['queue:default', Array]
110
- pushed = Sidekiq::Client.enqueue(MyWorker, 1, 2)
111
- assert pushed
112
- @redis.verify
113
- end
114
-
115
- it 'enqueues messages to redis' do
116
- @redis.expect :lpush, 1, ['queue:custom_queue', Array]
117
- pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
118
- assert pushed
119
- @redis.verify
120
- end
121
-
122
- it 'enqueues messages to redis (delayed, custom queue)' do
123
- @redis.expect :zadd, 1, ['schedule', Array]
124
- pushed = Sidekiq::Client.enqueue_to_in(:custom_queue, 3.minutes, MyWorker, 1, 2)
125
- assert pushed
126
- @redis.verify
127
- end
128
-
129
- it 'enqueues messages to redis (delayed into past, custom queue)' do
130
- @redis.expect :lpush, 1, ['queue:custom_queue', Array]
131
- pushed = Sidekiq::Client.enqueue_to_in(:custom_queue, -3.minutes, MyWorker, 1, 2)
132
- assert pushed
133
- @redis.verify
134
- end
135
-
136
- it 'enqueues messages to redis (delayed)' do
137
- @redis.expect :zadd, 1, ['schedule', Array]
138
- pushed = Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 1, 2)
139
- assert pushed
140
- @redis.verify
141
- end
142
-
143
- class QueuedWorker
144
- include Sidekiq::Worker
145
- sidekiq_options :queue => :flimflam
146
- end
147
-
148
- it 'enqueues to the named queue' do
149
- @redis.expect :lpush, 1, ['queue:flimflam', Array]
150
- pushed = QueuedWorker.perform_async(1, 2)
151
- assert pushed
152
- @redis.verify
153
- end
154
-
155
- it 'retrieves queues' do
156
- @redis.expect :smembers, ['bob'], ['queues']
157
- assert_equal ['bob'], Sidekiq::Queue.all.map(&:name)
158
- end
159
- end
160
-
161
- describe 'bulk' do
162
- after do
163
- Sidekiq::Queue.new.clear
164
- end
165
- it 'can push a large set of jobs at once' do
166
- jids = Sidekiq::Client.push_bulk('class' => QueuedWorker, 'args' => (1..1_000).to_a.map { |x| Array(x) })
167
- assert_equal 1_000, jids.size
168
- end
169
- it 'can push a large set of jobs at once using a String class' do
170
- jids = Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..1_000).to_a.map { |x| Array(x) })
171
- assert_equal 1_000, jids.size
172
- end
173
- it 'returns the jids for the jobs' do
174
- Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..2).to_a.map { |x| Array(x) }).each do |jid|
175
- assert_match(/[0-9a-f]{12}/, jid)
176
- end
177
- end
178
- end
179
-
180
- class BaseWorker
181
- include Sidekiq::Worker
182
- sidekiq_options 'retry' => 'base'
183
- end
184
- class AWorker < BaseWorker
185
- end
186
- class BWorker < BaseWorker
187
- sidekiq_options 'retry' => 'b'
188
- end
189
- class CWorker < BaseWorker
190
- sidekiq_options 'retry' => 2
191
- end
192
-
193
- describe 'client middleware' do
194
-
195
- class Stopper
196
- def call(worker_class, message, queue, r)
197
- raise ArgumentError unless r
198
- yield if message['args'].first.odd?
199
- end
200
- end
201
-
202
- it 'can stop some of the jobs from pushing' do
203
- Sidekiq.client_middleware.add Stopper
204
- begin
205
- assert_equal nil, Sidekiq::Client.push('class' => MyWorker, 'args' => [0])
206
- assert_match(/[0-9a-f]{12}/, Sidekiq::Client.push('class' => MyWorker, 'args' => [1]))
207
- Sidekiq::Client.push_bulk('class' => MyWorker, 'args' => [[0], [1]]).each do |jid|
208
- assert_match(/[0-9a-f]{12}/, jid)
209
- end
210
- ensure
211
- Sidekiq.client_middleware.remove Stopper
212
- end
213
- end
214
- end
215
-
216
- describe 'inheritance' do
217
- it 'inherits sidekiq options' do
218
- assert_equal 'base', AWorker.get_sidekiq_options['retry']
219
- assert_equal 'b', BWorker.get_sidekiq_options['retry']
220
- end
221
- end
222
-
223
- describe 'item normalization' do
224
- it 'defaults retry to true' do
225
- assert_equal true, Sidekiq::Client.new.__send__(:normalize_item, 'class' => QueuedWorker, 'args' => [])['retry']
226
- end
227
-
228
- it "does not normalize numeric retry's" do
229
- assert_equal 2, Sidekiq::Client.new.__send__(:normalize_item, 'class' => CWorker, 'args' => [])['retry']
230
- end
231
- end
232
-
233
- describe 'sharding' do
234
- class DWorker < BaseWorker
235
- end
236
- it 'allows sidekiq_options to point to different Redi' do
237
- conn = MiniTest::Mock.new
238
- conn.expect(:multi, [0, 1])
239
- DWorker.sidekiq_options('pool' => ConnectionPool.new(size: 1) { conn })
240
- DWorker.perform_async(1,2,3)
241
- conn.verify
242
- end
243
- it 'allows #via to point to different Redi' do
244
- conn = MiniTest::Mock.new
245
- conn.expect(:multi, [0, 1])
246
- default = Sidekiq::Client.new.redis_pool
247
- sharded_pool = ConnectionPool.new(size: 1) { conn }
248
- Sidekiq::Client.via(sharded_pool) do
249
- CWorker.perform_async(1,2,3)
250
- assert_equal sharded_pool, Sidekiq::Client.new.redis_pool
251
- assert_raises RuntimeError do
252
- Sidekiq::Client.via(default) do
253
- # nothing
254
- end
255
- end
256
- end
257
- assert_equal default, Sidekiq::Client.new.redis_pool
258
- conn.verify
259
- end
260
- it 'allows Resque helpers to point to different Redi' do
261
- conn = MiniTest::Mock.new
262
- conn.expect(:multi, []) { |*args, &block| block.call }
263
- conn.expect(:zadd, 1, [String, Array])
264
- DWorker.sidekiq_options('pool' => ConnectionPool.new(size: 1) { conn })
265
- Sidekiq::Client.enqueue_in(10, DWorker, 3)
266
- conn.verify
267
- end
268
- end
269
- end
@@ -1,55 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/exception_handler'
3
- require 'stringio'
4
- require 'logger'
5
-
6
- ExceptionHandlerTestException = Class.new(StandardError)
7
- TEST_EXCEPTION = ExceptionHandlerTestException.new("Something didn't work!")
8
-
9
- class Component
10
- include Sidekiq::ExceptionHandler
11
-
12
- def invoke_exception(args)
13
- raise TEST_EXCEPTION
14
- rescue ExceptionHandlerTestException => e
15
- handle_exception(e,args)
16
- end
17
- end
18
-
19
- class TestExceptionHandler < Sidekiq::Test
20
- describe "with mock logger" do
21
- before do
22
- @old_logger = Sidekiq.logger
23
- @str_logger = StringIO.new
24
- Sidekiq.logger = Logger.new(@str_logger)
25
- end
26
-
27
- after do
28
- Sidekiq.logger = @old_logger
29
- end
30
-
31
- it "logs the exception to Sidekiq.logger" do
32
- Component.new.invoke_exception(:a => 1)
33
- @str_logger.rewind
34
- log = @str_logger.readlines
35
- assert_match(/a=>1/, log[0], "didn't include the context")
36
- assert_match(/Something didn't work!/, log[1], "didn't include the exception message")
37
- assert_match(/test\/test_exception_handler.rb/, log[2], "didn't include the backtrace")
38
- end
39
-
40
- describe "when the exception does not have a backtrace" do
41
- it "does not fail" do
42
- exception = ExceptionHandlerTestException.new
43
- assert_nil exception.backtrace
44
-
45
- begin
46
- Component.new.handle_exception exception
47
- pass
48
- rescue StandardError
49
- flunk "failed handling a nil backtrace"
50
- end
51
- end
52
- end
53
- end
54
-
55
- end