-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsidekiq.rb
More file actions
90 lines (71 loc) · 1.95 KB
/
sidekiq.rb
File metadata and controls
90 lines (71 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require "singed/sidekiq"
RSpec.configure do |config|
config.before(:suite) do
Sidekiq.testing!(:inline)
Sidekiq::Client.prepend(SidekiqTestingInlineWithMiddlewares)
Sidekiq.configure_client do |config|
config.server_middleware do |chain|
chain.add Singed::Sidekiq::ServerMiddleware
end
end
ActiveJob::Base.queue_adapter = :sidekiq
ActiveJob::Base.logger = Logger.new(nil)
end
end
# Sidekiq doesn't invoke middlewares in inline testingmode, so we need to invoke it oursleves
module SidekiqTestingInlineWithMiddlewares
# rubocop:disable Metrics/AbcSize
def push(job)
return super unless Sidekiq::Testing.inline?
job = Sidekiq.load_json(Sidekiq.dump_json(job))
job["jid"] ||= SecureRandom.hex(12)
job_class = Object.const_get(job["class"])
job_instance = job_class.new
queue = (job_instance.sidekiq_options_hash || {}).fetch("queue", "default")
server = Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq
server.server_middleware.invoke(job_instance, job, queue) do
job_instance.perform(*job["args"])
end
job["jid"]
end
# rubocop:enable Metrics/AbcSize
end
class SidekiqPlainJob
include Sidekiq::Job
def perform(*_args)
"My job is simple"
end
end
class SidekiqFlamegraphJob
include Sidekiq::Job
def self.capture_flamegraph?(payload)
!!payload["x-flamegraph"]
end
def perform(*_args)
"Phew, I'm done!"
end
end
class ActiveJobPlainJob < ActiveJob::Base
self.queue_adapter = :sidekiq
def perform(*_args)
"My job is simple"
end
end
class ActiveJobFlamegraphJob < ActiveJob::Base
self.queue_adapter = :sidekiq
def self.capture_flamegraph?(_payload)
true
end
def perform(*_args)
"Phew, I'm done!"
end
end
class ActiveJobNoFlamegraphJob < ActiveJob::Base
self.queue_adapter = :sidekiq
def self.capture_flamegraph?(_payload)
false
end
def perform(*_args)
"Phew, I'm done!"
end
end