sidekiq 4.2.10 → 6.5.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/Changes.md +573 -1
- data/LICENSE +3 -3
- data/README.md +25 -34
- data/bin/sidekiq +27 -3
- data/bin/sidekiqload +81 -74
- data/bin/sidekiqmon +8 -0
- data/lib/generators/sidekiq/job_generator.rb +57 -0
- data/lib/generators/sidekiq/templates/{worker.rb.erb → job.rb.erb} +2 -2
- data/lib/generators/sidekiq/templates/job_spec.rb.erb +6 -0
- data/lib/generators/sidekiq/templates/{worker_test.rb.erb → job_test.rb.erb} +1 -1
- data/lib/sidekiq/api.rb +585 -285
- data/lib/sidekiq/cli.rb +256 -233
- data/lib/sidekiq/client.rb +86 -83
- data/lib/sidekiq/component.rb +65 -0
- data/lib/sidekiq/delay.rb +43 -0
- data/lib/sidekiq/extensions/action_mailer.rb +13 -22
- data/lib/sidekiq/extensions/active_record.rb +13 -10
- data/lib/sidekiq/extensions/class_methods.rb +14 -11
- data/lib/sidekiq/extensions/generic_proxy.rb +13 -5
- data/lib/sidekiq/fetch.rb +50 -40
- data/lib/sidekiq/job.rb +13 -0
- data/lib/sidekiq/job_logger.rb +51 -0
- data/lib/sidekiq/job_retry.rb +282 -0
- data/lib/sidekiq/job_util.rb +71 -0
- data/lib/sidekiq/launcher.rb +184 -90
- data/lib/sidekiq/logger.rb +156 -0
- data/lib/sidekiq/manager.rb +43 -45
- data/lib/sidekiq/metrics/deploy.rb +47 -0
- data/lib/sidekiq/metrics/query.rb +153 -0
- data/lib/sidekiq/metrics/shared.rb +94 -0
- data/lib/sidekiq/metrics/tracking.rb +134 -0
- data/lib/sidekiq/middleware/chain.rb +102 -46
- data/lib/sidekiq/middleware/current_attributes.rb +63 -0
- data/lib/sidekiq/middleware/i18n.rb +7 -7
- data/lib/sidekiq/middleware/modules.rb +21 -0
- data/lib/sidekiq/monitor.rb +133 -0
- data/lib/sidekiq/paginator.rb +20 -16
- data/lib/sidekiq/processor.rb +176 -91
- data/lib/sidekiq/rails.rb +41 -96
- data/lib/sidekiq/redis_client_adapter.rb +154 -0
- data/lib/sidekiq/redis_connection.rb +117 -48
- data/lib/sidekiq/ring_buffer.rb +29 -0
- data/lib/sidekiq/scheduled.rb +134 -44
- data/lib/sidekiq/sd_notify.rb +149 -0
- data/lib/sidekiq/systemd.rb +24 -0
- data/lib/sidekiq/testing/inline.rb +6 -5
- data/lib/sidekiq/testing.rb +80 -61
- data/lib/sidekiq/transaction_aware_client.rb +45 -0
- data/lib/sidekiq/version.rb +2 -1
- data/lib/sidekiq/web/action.rb +15 -15
- data/lib/sidekiq/web/application.rb +129 -86
- data/lib/sidekiq/web/csrf_protection.rb +180 -0
- data/lib/sidekiq/web/helpers.rb +170 -83
- data/lib/sidekiq/web/router.rb +23 -19
- data/lib/sidekiq/web.rb +69 -109
- data/lib/sidekiq/worker.rb +290 -41
- data/lib/sidekiq.rb +185 -77
- data/sidekiq.gemspec +23 -27
- data/web/assets/images/apple-touch-icon.png +0 -0
- data/web/assets/javascripts/application.js +112 -61
- data/web/assets/javascripts/chart.min.js +13 -0
- data/web/assets/javascripts/chartjs-plugin-annotation.min.js +7 -0
- data/web/assets/javascripts/dashboard.js +70 -91
- data/web/assets/javascripts/graph.js +16 -0
- data/web/assets/javascripts/metrics.js +262 -0
- data/web/assets/stylesheets/application-dark.css +143 -0
- data/web/assets/stylesheets/application-rtl.css +242 -0
- data/web/assets/stylesheets/application.css +364 -144
- data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
- data/web/assets/stylesheets/bootstrap.css +2 -2
- data/web/locales/ar.yml +87 -0
- data/web/locales/de.yml +14 -2
- data/web/locales/el.yml +43 -19
- data/web/locales/en.yml +15 -1
- data/web/locales/es.yml +22 -5
- data/web/locales/fa.yml +1 -0
- data/web/locales/fr.yml +10 -3
- data/web/locales/he.yml +79 -0
- data/web/locales/ja.yml +19 -4
- data/web/locales/lt.yml +83 -0
- data/web/locales/pl.yml +4 -4
- data/web/locales/pt-br.yml +27 -9
- data/web/locales/ru.yml +4 -0
- data/web/locales/ur.yml +80 -0
- data/web/locales/vi.yml +83 -0
- data/web/locales/zh-cn.yml +36 -11
- data/web/locales/zh-tw.yml +32 -7
- data/web/views/_footer.erb +5 -2
- data/web/views/_job_info.erb +3 -2
- data/web/views/_nav.erb +5 -19
- data/web/views/_paging.erb +1 -1
- data/web/views/_poll_link.erb +2 -5
- data/web/views/_summary.erb +7 -7
- data/web/views/busy.erb +62 -24
- data/web/views/dashboard.erb +24 -15
- data/web/views/dead.erb +3 -3
- data/web/views/layout.erb +14 -3
- data/web/views/metrics.erb +69 -0
- data/web/views/metrics_for_job.erb +87 -0
- data/web/views/morgue.erb +9 -6
- data/web/views/queue.erb +26 -12
- data/web/views/queues.erb +12 -2
- data/web/views/retries.erb +14 -7
- data/web/views/retry.erb +3 -3
- data/web/views/scheduled.erb +7 -4
- metadata +66 -206
- data/.github/contributing.md +0 -32
- data/.github/issue_template.md +0 -9
- data/.gitignore +0 -12
- data/.travis.yml +0 -18
- data/3.0-Upgrade.md +0 -70
- data/4.0-Upgrade.md +0 -53
- data/COMM-LICENSE +0 -95
- data/Ent-Changes.md +0 -173
- data/Gemfile +0 -29
- data/Pro-2.0-Upgrade.md +0 -138
- data/Pro-3.0-Upgrade.md +0 -44
- data/Pro-Changes.md +0 -628
- data/Rakefile +0 -12
- data/bin/sidekiqctl +0 -99
- data/code_of_conduct.md +0 -50
- data/lib/generators/sidekiq/templates/worker_spec.rb.erb +0 -6
- data/lib/generators/sidekiq/worker_generator.rb +0 -49
- data/lib/sidekiq/core_ext.rb +0 -119
- data/lib/sidekiq/exception_handler.rb +0 -31
- data/lib/sidekiq/logging.rb +0 -106
- data/lib/sidekiq/middleware/server/active_record.rb +0 -13
- data/lib/sidekiq/middleware/server/logging.rb +0 -31
- data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -205
- data/lib/sidekiq/util.rb +0 -63
data/lib/sidekiq/testing.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'securerandom'
|
3
|
-
require 'sidekiq'
|
4
2
|
|
5
|
-
|
3
|
+
require "securerandom"
|
4
|
+
require "sidekiq"
|
6
5
|
|
6
|
+
module Sidekiq
|
7
7
|
class Testing
|
8
8
|
class << self
|
9
9
|
attr_accessor :__test_mode
|
10
10
|
|
11
11
|
def __set_test_mode(mode)
|
12
12
|
if block_given?
|
13
|
-
current_mode =
|
13
|
+
current_mode = __test_mode
|
14
14
|
begin
|
15
15
|
self.__test_mode = mode
|
16
16
|
yield
|
@@ -35,19 +35,19 @@ module Sidekiq
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def enabled?
|
38
|
-
|
38
|
+
__test_mode != :disable
|
39
39
|
end
|
40
40
|
|
41
41
|
def disabled?
|
42
|
-
|
42
|
+
__test_mode == :disable
|
43
43
|
end
|
44
44
|
|
45
45
|
def fake?
|
46
|
-
|
46
|
+
__test_mode == :fake
|
47
47
|
end
|
48
48
|
|
49
49
|
def inline?
|
50
|
-
|
50
|
+
__test_mode == :inline
|
51
51
|
end
|
52
52
|
|
53
53
|
def server_middleware
|
@@ -55,6 +55,15 @@ module Sidekiq
|
|
55
55
|
yield @server_chain if block_given?
|
56
56
|
@server_chain
|
57
57
|
end
|
58
|
+
|
59
|
+
def constantize(str)
|
60
|
+
names = str.split("::")
|
61
|
+
names.shift if names.empty? || names.first.empty?
|
62
|
+
|
63
|
+
names.inject(Object) do |constant, name|
|
64
|
+
constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
65
|
+
end
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
|
@@ -63,49 +72,49 @@ module Sidekiq
|
|
63
72
|
|
64
73
|
class EmptyQueueError < RuntimeError; end
|
65
74
|
|
66
|
-
|
67
|
-
alias_method :raw_push_real, :raw_push
|
68
|
-
|
75
|
+
module TestingClient
|
69
76
|
def raw_push(payloads)
|
70
77
|
if Sidekiq::Testing.fake?
|
71
78
|
payloads.each do |job|
|
72
79
|
job = Sidekiq.load_json(Sidekiq.dump_json(job))
|
73
|
-
job
|
74
|
-
Queues.push(job[
|
80
|
+
job["enqueued_at"] = Time.now.to_f unless job["at"]
|
81
|
+
Queues.push(job["queue"], job["class"], job)
|
75
82
|
end
|
76
83
|
true
|
77
84
|
elsif Sidekiq::Testing.inline?
|
78
85
|
payloads.each do |job|
|
79
|
-
klass = job[
|
80
|
-
job[
|
86
|
+
klass = Sidekiq::Testing.constantize(job["class"])
|
87
|
+
job["id"] ||= SecureRandom.hex(12)
|
81
88
|
job_hash = Sidekiq.load_json(Sidekiq.dump_json(job))
|
82
89
|
klass.process_job(job_hash)
|
83
90
|
end
|
84
91
|
true
|
85
92
|
else
|
86
|
-
|
93
|
+
super
|
87
94
|
end
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
98
|
+
Sidekiq::Client.prepend TestingClient
|
99
|
+
|
91
100
|
module Queues
|
92
101
|
##
|
93
102
|
# The Queues class is only for testing the fake queue implementation.
|
94
103
|
# There are 2 data structures involved in tandem. This is due to the
|
95
|
-
# Rspec syntax of change(
|
104
|
+
# Rspec syntax of change(HardJob.jobs, :size). It keeps a reference
|
96
105
|
# to the array. Because the array was dervied from a filter of the total
|
97
106
|
# jobs enqueued, it appeared as though the array didn't change.
|
98
107
|
#
|
99
108
|
# To solve this, we'll keep 2 hashes containing the jobs. One with keys based
|
100
|
-
# on the queue, and another with keys of the
|
101
|
-
#
|
109
|
+
# on the queue, and another with keys of the job type, so the array for
|
110
|
+
# HardJob.jobs is a straight reference to a real array.
|
102
111
|
#
|
103
112
|
# Queue-based hash:
|
104
113
|
#
|
105
114
|
# {
|
106
115
|
# "default"=>[
|
107
116
|
# {
|
108
|
-
# "class"=>"TestTesting::
|
117
|
+
# "class"=>"TestTesting::HardJob",
|
109
118
|
# "args"=>[1, 2],
|
110
119
|
# "retry"=>true,
|
111
120
|
# "queue"=>"default",
|
@@ -115,12 +124,12 @@ module Sidekiq
|
|
115
124
|
# ]
|
116
125
|
# }
|
117
126
|
#
|
118
|
-
#
|
127
|
+
# Job-based hash:
|
119
128
|
#
|
120
129
|
# {
|
121
|
-
# "TestTesting::
|
130
|
+
# "TestTesting::HardJob"=>[
|
122
131
|
# {
|
123
|
-
# "class"=>"TestTesting::
|
132
|
+
# "class"=>"TestTesting::HardJob",
|
124
133
|
# "args"=>[1, 2],
|
125
134
|
# "retry"=>true,
|
126
135
|
# "queue"=>"default",
|
@@ -135,14 +144,14 @@ module Sidekiq
|
|
135
144
|
# require 'sidekiq/testing'
|
136
145
|
#
|
137
146
|
# assert_equal 0, Sidekiq::Queues["default"].size
|
138
|
-
#
|
147
|
+
# HardJob.perform_async(:something)
|
139
148
|
# assert_equal 1, Sidekiq::Queues["default"].size
|
140
149
|
# assert_equal :something, Sidekiq::Queues["default"].first['args'][0]
|
141
150
|
#
|
142
|
-
# You can also clear all
|
151
|
+
# You can also clear all jobs:
|
143
152
|
#
|
144
153
|
# assert_equal 0, Sidekiq::Queues["default"].size
|
145
|
-
#
|
154
|
+
# HardJob.perform_async(:something)
|
146
155
|
# Sidekiq::Queues.clear_all
|
147
156
|
# assert_equal 0, Sidekiq::Queues["default"].size
|
148
157
|
#
|
@@ -161,35 +170,36 @@ module Sidekiq
|
|
161
170
|
|
162
171
|
def push(queue, klass, job)
|
163
172
|
jobs_by_queue[queue] << job
|
164
|
-
|
173
|
+
jobs_by_class[klass] << job
|
165
174
|
end
|
166
175
|
|
167
176
|
def jobs_by_queue
|
168
177
|
@jobs_by_queue ||= Hash.new { |hash, key| hash[key] = [] }
|
169
178
|
end
|
170
179
|
|
171
|
-
def
|
172
|
-
@
|
180
|
+
def jobs_by_class
|
181
|
+
@jobs_by_class ||= Hash.new { |hash, key| hash[key] = [] }
|
173
182
|
end
|
183
|
+
alias_method :jobs_by_worker, :jobs_by_class
|
174
184
|
|
175
185
|
def delete_for(jid, queue, klass)
|
176
186
|
jobs_by_queue[queue.to_s].delete_if { |job| job["jid"] == jid }
|
177
|
-
|
187
|
+
jobs_by_class[klass].delete_if { |job| job["jid"] == jid }
|
178
188
|
end
|
179
189
|
|
180
190
|
def clear_for(queue, klass)
|
181
|
-
jobs_by_queue[queue].clear
|
182
|
-
|
191
|
+
jobs_by_queue[queue.to_s].clear
|
192
|
+
jobs_by_class[klass].clear
|
183
193
|
end
|
184
194
|
|
185
195
|
def clear_all
|
186
196
|
jobs_by_queue.clear
|
187
|
-
|
197
|
+
jobs_by_class.clear
|
188
198
|
end
|
189
199
|
end
|
190
200
|
end
|
191
201
|
|
192
|
-
module
|
202
|
+
module Job
|
193
203
|
##
|
194
204
|
# The Sidekiq testing infrastructure overrides perform_async
|
195
205
|
# so that it does not actually touch the network. Instead it
|
@@ -203,16 +213,16 @@ module Sidekiq
|
|
203
213
|
#
|
204
214
|
# require 'sidekiq/testing'
|
205
215
|
#
|
206
|
-
# assert_equal 0,
|
207
|
-
#
|
208
|
-
# assert_equal 1,
|
209
|
-
# assert_equal :something,
|
216
|
+
# assert_equal 0, HardJob.jobs.size
|
217
|
+
# HardJob.perform_async(:something)
|
218
|
+
# assert_equal 1, HardJob.jobs.size
|
219
|
+
# assert_equal :something, HardJob.jobs[0]['args'][0]
|
210
220
|
#
|
211
221
|
# assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
|
212
222
|
# MyMailer.delay.send_welcome_email('foo@example.com')
|
213
223
|
# assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
|
214
224
|
#
|
215
|
-
# You can also clear and drain all
|
225
|
+
# You can also clear and drain all job types:
|
216
226
|
#
|
217
227
|
# assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
|
218
228
|
# assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
|
@@ -232,41 +242,40 @@ module Sidekiq
|
|
232
242
|
#
|
233
243
|
# RSpec.configure do |config|
|
234
244
|
# config.before(:each) do
|
235
|
-
# Sidekiq::
|
245
|
+
# Sidekiq::Job.clear_all
|
236
246
|
# end
|
237
247
|
# end
|
238
248
|
#
|
239
249
|
# or for acceptance testing, i.e. with cucumber:
|
240
250
|
#
|
241
251
|
# AfterStep do
|
242
|
-
# Sidekiq::
|
252
|
+
# Sidekiq::Job.drain_all
|
243
253
|
# end
|
244
254
|
#
|
245
255
|
# When I sign up as "foo@example.com"
|
246
256
|
# Then I should receive a welcome email to "foo@example.com"
|
247
257
|
#
|
248
258
|
module ClassMethods
|
249
|
-
|
250
259
|
# Queue for this worker
|
251
260
|
def queue
|
252
|
-
|
261
|
+
get_sidekiq_options["queue"]
|
253
262
|
end
|
254
263
|
|
255
264
|
# Jobs queued for this worker
|
256
265
|
def jobs
|
257
|
-
Queues.
|
266
|
+
Queues.jobs_by_class[to_s]
|
258
267
|
end
|
259
268
|
|
260
269
|
# Clear all jobs for this worker
|
261
270
|
def clear
|
262
|
-
Queues.clear_for(queue,
|
271
|
+
Queues.clear_for(queue, to_s)
|
263
272
|
end
|
264
273
|
|
265
274
|
# Drain and run all jobs for this worker
|
266
275
|
def drain
|
267
276
|
while jobs.any?
|
268
277
|
next_job = jobs.first
|
269
|
-
Queues.delete_for(next_job["jid"], next_job["queue"],
|
278
|
+
Queues.delete_for(next_job["jid"], next_job["queue"], to_s)
|
270
279
|
process_job(next_job)
|
271
280
|
end
|
272
281
|
end
|
@@ -275,16 +284,16 @@ module Sidekiq
|
|
275
284
|
def perform_one
|
276
285
|
raise(EmptyQueueError, "perform_one called with empty job queue") if jobs.empty?
|
277
286
|
next_job = jobs.first
|
278
|
-
Queues.delete_for(next_job["jid"], queue,
|
287
|
+
Queues.delete_for(next_job["jid"], queue, to_s)
|
279
288
|
process_job(next_job)
|
280
289
|
end
|
281
290
|
|
282
291
|
def process_job(job)
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
Sidekiq::Testing.server_middleware.invoke(
|
287
|
-
execute_job(
|
292
|
+
inst = new
|
293
|
+
inst.jid = job["jid"]
|
294
|
+
inst.bid = job["bid"] if inst.respond_to?(:bid=)
|
295
|
+
Sidekiq::Testing.server_middleware.invoke(inst, job, job["queue"]) do
|
296
|
+
execute_job(inst, job["args"])
|
288
297
|
end
|
289
298
|
end
|
290
299
|
|
@@ -298,27 +307,37 @@ module Sidekiq
|
|
298
307
|
Queues.jobs_by_queue.values.flatten
|
299
308
|
end
|
300
309
|
|
301
|
-
# Clear all queued jobs
|
310
|
+
# Clear all queued jobs
|
302
311
|
def clear_all
|
303
312
|
Queues.clear_all
|
304
313
|
end
|
305
314
|
|
306
|
-
# Drain all queued jobs
|
315
|
+
# Drain (execute) all queued jobs
|
307
316
|
def drain_all
|
308
317
|
while jobs.any?
|
309
|
-
|
318
|
+
job_classes = jobs.map { |job| job["class"] }.uniq
|
310
319
|
|
311
|
-
|
312
|
-
|
320
|
+
job_classes.each do |job_class|
|
321
|
+
Sidekiq::Testing.constantize(job_class).drain
|
313
322
|
end
|
314
323
|
end
|
315
324
|
end
|
316
325
|
end
|
317
326
|
end
|
327
|
+
|
328
|
+
module TestingExtensions
|
329
|
+
def jobs_for(klass)
|
330
|
+
jobs.select do |job|
|
331
|
+
marshalled = job["args"][0]
|
332
|
+
marshalled.index(klass.to_s) && YAML.load(marshalled)[0] == klass
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
Sidekiq::Extensions::DelayedMailer.extend(TestingExtensions) if defined?(Sidekiq::Extensions::DelayedMailer)
|
338
|
+
Sidekiq::Extensions::DelayedModel.extend(TestingExtensions) if defined?(Sidekiq::Extensions::DelayedModel)
|
318
339
|
end
|
319
340
|
|
320
|
-
if defined?(::Rails) && !Rails.env.test?
|
321
|
-
|
322
|
-
puts("⛔️ WARNING: Sidekiq testing API enabled, but this is not the test environment. Your jobs will not go to Redis.")
|
323
|
-
puts("**************************************************")
|
341
|
+
if defined?(::Rails) && Rails.respond_to?(:env) && !Rails.env.test? && !$TESTING
|
342
|
+
warn("⛔️ WARNING: Sidekiq testing API enabled, but this is not the test environment. Your jobs will not go to Redis.", uplevel: 1)
|
324
343
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
require "sidekiq/client"
|
5
|
+
|
6
|
+
module Sidekiq
|
7
|
+
class TransactionAwareClient
|
8
|
+
def initialize(redis_pool)
|
9
|
+
@redis_client = Client.new(redis_pool)
|
10
|
+
end
|
11
|
+
|
12
|
+
def push(item)
|
13
|
+
# pre-allocate the JID so we can return it immediately and
|
14
|
+
# save it to the database as part of the transaction.
|
15
|
+
item["jid"] ||= SecureRandom.hex(12)
|
16
|
+
AfterCommitEverywhere.after_commit { @redis_client.push(item) }
|
17
|
+
item["jid"]
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# We don't provide transactionality for push_bulk because we don't want
|
22
|
+
# to hold potentially hundreds of thousands of job records in memory due to
|
23
|
+
# a long running enqueue process.
|
24
|
+
def push_bulk(items)
|
25
|
+
@redis_client.push_bulk(items)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Use `Sidekiq.transactional_push!` in your sidekiq.rb initializer
|
32
|
+
module Sidekiq
|
33
|
+
def self.transactional_push!
|
34
|
+
begin
|
35
|
+
require "after_commit_everywhere"
|
36
|
+
rescue LoadError
|
37
|
+
Sidekiq.logger.error("You need to add after_commit_everywhere to your Gemfile to use Sidekiq's transactional client")
|
38
|
+
raise
|
39
|
+
end
|
40
|
+
|
41
|
+
default_job_options["client_class"] = Sidekiq::TransactionAwareClient
|
42
|
+
Sidekiq::JobUtil::TRANSIENT_ATTRIBUTES << "client_class"
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
data/lib/sidekiq/version.rb
CHANGED
data/lib/sidekiq/web/action.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Sidekiq
|
4
4
|
class WebAction
|
5
|
-
RACK_SESSION =
|
5
|
+
RACK_SESSION = "rack.session"
|
6
6
|
|
7
7
|
attr_accessor :env, :block, :type
|
8
8
|
|
@@ -15,18 +15,18 @@ module Sidekiq
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def halt(res)
|
18
|
-
throw :halt, res
|
18
|
+
throw :halt, [res, {"content-type" => "text/plain"}, [res.to_s]]
|
19
19
|
end
|
20
20
|
|
21
21
|
def redirect(location)
|
22
|
-
throw :halt, [302, {
|
22
|
+
throw :halt, [302, {"location" => "#{request.base_url}#{location}"}, []]
|
23
23
|
end
|
24
24
|
|
25
25
|
def params
|
26
|
-
indifferent_hash = Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
26
|
+
indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key }
|
27
27
|
|
28
28
|
indifferent_hash.merge! request.params
|
29
|
-
route_params.each {|k,v| indifferent_hash[k.to_s] = v }
|
29
|
+
route_params.each { |k, v| indifferent_hash[k.to_s] = v }
|
30
30
|
|
31
31
|
indifferent_hash
|
32
32
|
end
|
@@ -39,15 +39,15 @@ module Sidekiq
|
|
39
39
|
env[RACK_SESSION]
|
40
40
|
end
|
41
41
|
|
42
|
-
def content_type(type)
|
43
|
-
@type = type
|
44
|
-
end
|
45
|
-
|
46
42
|
def erb(content, options = {})
|
47
|
-
if content.
|
43
|
+
if content.is_a? Symbol
|
48
44
|
unless respond_to?(:"_erb_#{content}")
|
49
45
|
src = ERB.new(File.read("#{Web.settings.views}/#{content}.erb")).src
|
50
|
-
WebAction.class_eval
|
46
|
+
WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
47
|
+
def _erb_#{content}
|
48
|
+
#{src}
|
49
|
+
end
|
50
|
+
RUBY
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -68,22 +68,22 @@ module Sidekiq
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def json(payload)
|
71
|
-
[200, {
|
71
|
+
[200, {"content-type" => "application/json", "cache-control" => "private, no-store"}, [Sidekiq.dump_json(payload)]]
|
72
72
|
end
|
73
73
|
|
74
74
|
def initialize(env, block)
|
75
75
|
@_erb = false
|
76
76
|
@env = env
|
77
77
|
@block = block
|
78
|
-
|
78
|
+
@files ||= {}
|
79
79
|
end
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
83
|
def _erb(file, locals)
|
84
|
-
locals
|
84
|
+
locals&.each { |k, v| define_singleton_method(k) { v } unless singleton_methods.include? k }
|
85
85
|
|
86
|
-
if file.
|
86
|
+
if file.is_a?(String)
|
87
87
|
ERB.new(file).result(binding)
|
88
88
|
else
|
89
89
|
send(:"_erb_#{file}")
|