boy_band 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/boy_band.rb +35 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7584b735b0671735458dcf190fac4d6469b4fc3e165e9df54f909bceaa89b83
|
4
|
+
data.tar.gz: 691d966ef8eabf44ec431cf4a182ca81b10202c17f96c0f88d5a702ff6492eb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06723c500fc807e94c6f1937154033dd87d82f9c3ce53d4cc699a4b6071ddbb3f180100a2d9a0cb002dee06b87c9a8248326b8de84cf03953d54423e8e44197e
|
7
|
+
data.tar.gz: 61166b0bc26eae3181cbf10f195bfb461199cc0f40839f7717a8765abac549dc632826bf2160dc4fef5bff08fec1ffb8c528c999746da2e3b5cfcdb47105329e
|
data/lib/boy_band.rb
CHANGED
@@ -16,7 +16,7 @@ module BoyBand
|
|
16
16
|
PaperTrail.whodunnit = name
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
module WorkerMethods
|
21
21
|
def thread_id
|
22
22
|
"#{Process.pid}_#{Thread.current.object_id}"
|
@@ -31,12 +31,34 @@ module BoyBand
|
|
31
31
|
@@domain_id = val
|
32
32
|
end
|
33
33
|
|
34
|
+
def job_chain
|
35
|
+
@@job_chain ||= "none"
|
36
|
+
@@job_chain
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_job_chain(val)
|
40
|
+
@@job_chain = val
|
41
|
+
end
|
42
|
+
|
34
43
|
def schedule_for(queue, klass, method_name, *args)
|
35
44
|
@queue = queue.to_s
|
36
45
|
job_hash = Digest::MD5.hexdigest(args.to_json)
|
37
46
|
note_job(job_hash)
|
38
47
|
size = Resque.size(queue)
|
39
48
|
args.push("domain::#{self.domain_id}")
|
49
|
+
chain = self.job_chain.split(/##/)
|
50
|
+
job_id = "j#{Time.now.iso8601}_#{rand(9999)}"
|
51
|
+
chain = [job_id] if chain == ["none"]
|
52
|
+
if chain.length > 1
|
53
|
+
Resque.redis.incr("jobs_from_#{chain[0]}")
|
54
|
+
Resque.redis.expire("jobs_from_#{chain[0]}", 24.hours.to_i)
|
55
|
+
end
|
56
|
+
chain.push("#{klass.to_s},#{method_name.to_s},#{args.join('+')}")
|
57
|
+
Rails.logger.warn("jobchain set, #{chain[0]} #{chain.join('##')}") if chain.length > 1
|
58
|
+
if chain.length > 5
|
59
|
+
Rails.logger.error("jobchain too long: job_id, #{chain.length} entries")
|
60
|
+
end
|
61
|
+
args.push("chain::#{chain.join('##')}")
|
40
62
|
if queue == :slow
|
41
63
|
Resque.enqueue(SlowWorker, klass.to_s, method_name, *args)
|
42
64
|
if size > 1000 && !Resque.redis.get("queue_warning_#{queue}")
|
@@ -88,7 +110,10 @@ module BoyBand
|
|
88
110
|
|
89
111
|
def perform_at(speed, *args)
|
90
112
|
args_copy = [] + args
|
91
|
-
if
|
113
|
+
if args_copy[-1].is_a?(String) && args_copy[-1].match(/^chain::/)
|
114
|
+
set_job_chain(args_copy.pop.split(/::/, 2)[1])
|
115
|
+
end
|
116
|
+
if args_copy[-1].is_a?(String) && args_copy[-1].match(/^domain::/)
|
92
117
|
set_domain_id(args_copy.pop.split(/::/, 2)[1])
|
93
118
|
end
|
94
119
|
klass_string = args_copy.shift
|
@@ -112,6 +137,7 @@ module BoyBand
|
|
112
137
|
elsif diff > 60*10 && speed == :slow
|
113
138
|
Rails.logger.error("long-running job, #{action} (expected slow), #{diff}s")
|
114
139
|
end
|
140
|
+
set_job_chain("none")
|
115
141
|
BoyBand.set_job_instigator(pre_whodunnit)
|
116
142
|
clear_job(job_hash)
|
117
143
|
rescue Resque::TermException
|
@@ -136,6 +162,9 @@ module BoyBand
|
|
136
162
|
idx = Resque.size(queue)
|
137
163
|
idx.times do |i|
|
138
164
|
item = Resque.peek(queue, i)
|
165
|
+
if item['args'] && item['args'][-1].match(/^chain::/)
|
166
|
+
chain = item['args'].pop
|
167
|
+
end
|
139
168
|
if item['args'] && item['args'][-1].match(/^domain::/)
|
140
169
|
domain = item['args'].pop
|
141
170
|
item['domain_id'] = domain.split(/::/, 2)[1]
|
@@ -148,6 +177,9 @@ module BoyBand
|
|
148
177
|
|
149
178
|
def scheduled_for?(queue, klass, method_name, *args)
|
150
179
|
args_copy = [] + args
|
180
|
+
if args[-1].is_a?(String) && args[-1].match(/^chain::/)
|
181
|
+
args_copy.pop.split(/::/, 2)[1]
|
182
|
+
end
|
151
183
|
if args[-1].is_a?(String) && args[-1].match(/^domain::/)
|
152
184
|
set_domain_id(args_copy.pop.split(/::/, 2)[1])
|
153
185
|
end
|
@@ -173,6 +205,7 @@ module BoyBand
|
|
173
205
|
a1[0].delete('domain_id')
|
174
206
|
end
|
175
207
|
a2 = schedule['args'][2..-1]
|
208
|
+
a2.pop if a2.length > 1 && a2[-1].is_a?(String) && a2[-1].match(/^chain::/)
|
176
209
|
a2.pop if a2.length > 1 && a2[-1].is_a?(String) && a2[-1].match(/^domain::/)
|
177
210
|
if a2.length == 1 && a2[0].is_a?(Hash)
|
178
211
|
a2 = [a2[0].dup]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boy_band
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|