boy_band 0.1.8 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/boy_band.rb +51 -46
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd78f34f6e59840ca1c26e224ae07c6c00474d359b251cc510bbe73206b7091
|
4
|
+
data.tar.gz: d1fd4e70195819e3a7e176323e9c0a73027c18aeee6fa643e8d1bbf01669d649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6caebc3b98d4caa82b28f16a9491b35ebf82afcf0e5bbd5fbeba65389ecb6cbb103188073f4a3b55acbb8862d05fd6388a9aae9afcbd1fb871518b03ab68f266
|
7
|
+
data.tar.gz: d145d07df99f98d0827e4126d349bbf26c33a877452fbb729948c0f70992c4ee9c73aa942ff6c3ee33b3587070290060f403baa04cbf54fc2face5a2aaaef96b
|
data/lib/boy_band.rb
CHANGED
@@ -39,12 +39,22 @@ module BoyBand
|
|
39
39
|
def set_job_chain(val)
|
40
40
|
@@job_chain = val
|
41
41
|
end
|
42
|
+
|
43
|
+
def queue_size(queue)
|
44
|
+
size = Resque.redis.get("sizeof/#{queue}").to_i
|
45
|
+
if !size || size == 0
|
46
|
+
size = Resque.size(queue)
|
47
|
+
Resque.redis.setex("sizeof/#{queue}", 30.seconds.to_i, size)
|
48
|
+
end
|
49
|
+
size
|
50
|
+
end
|
42
51
|
|
43
52
|
def schedule_for(queue, klass, method_name, *args)
|
53
|
+
queue = queue.to_sym
|
44
54
|
@queue = queue.to_s
|
45
55
|
job_hash = Digest::MD5.hexdigest(args.to_json)
|
46
56
|
note_job(job_hash)
|
47
|
-
size =
|
57
|
+
size = queue_size(queue)
|
48
58
|
args.push("domain::#{self.domain_id}")
|
49
59
|
chain = self.job_chain.split(/##/)
|
50
60
|
job_id = "j#{Time.now.iso8601}_#{rand(9999)}"
|
@@ -53,14 +63,19 @@ module BoyBand
|
|
53
63
|
Resque.redis.incr("jobs_from_#{chain[0]}")
|
54
64
|
Resque.redis.expire("jobs_from_#{chain[0]}", 24.hours.to_i)
|
55
65
|
end
|
56
|
-
|
57
|
-
|
66
|
+
Resque.redis.setex("scheduled/#{klass.to_s}/#{job_hash}", 6.hours, "t")
|
67
|
+
chain_args = args[0..-2]
|
68
|
+
if chain_args.length == 1 && chain_args[0].is_a?(Hash)
|
69
|
+
chain_args = [chain_args[0]['method'],chain_args[0]['id'],chain_args[0]['arguments'].to_s[0, 20]]
|
70
|
+
end
|
71
|
+
chain.push("#{klass.to_s},#{method_name.to_s},#{chain_args.join('+')}")
|
72
|
+
# Rails.logger.warn("jobchain set, #{chain[0]} #{chain.join('##')}") if chain.length > 2
|
58
73
|
if chain.length > 5
|
59
|
-
Rails.logger.error("jobchain too deep: #{chain[
|
74
|
+
Rails.logger.error("jobchain too deep: #{chain[1]}, #{chain.length} entries")
|
60
75
|
end
|
61
76
|
job_count = Resque.redis.get("jobs_from_#{chain[0]}")
|
62
77
|
if job_count && job_count.to_i > 50
|
63
|
-
Rails.logger.error("jobchain too many sub-jobs: #{chain[
|
78
|
+
Rails.logger.error("jobchain too many sub-jobs: #{chain[1]}, #{job_count} so far")
|
64
79
|
end
|
65
80
|
args.push("chain::#{chain.join('##')}")
|
66
81
|
if queue == :slow
|
@@ -79,21 +94,21 @@ module BoyBand
|
|
79
94
|
end
|
80
95
|
|
81
96
|
def note_job(hash)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
# Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
|
88
|
-
|
97
|
+
# if Resque.redis
|
98
|
+
# timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
|
99
|
+
# cutoff = 6.hours.ago.to_i
|
100
|
+
# timestamps = timestamps.select{|ts| ts > cutoff }
|
101
|
+
# timestamps.push(Time.now.to_i)
|
102
|
+
# # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
|
103
|
+
# end
|
89
104
|
end
|
90
105
|
|
91
106
|
def clear_job(hash)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
|
96
|
-
|
107
|
+
# if Resque.redis
|
108
|
+
# timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
|
109
|
+
# timestamps.shift
|
110
|
+
# # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
|
111
|
+
# end
|
97
112
|
end
|
98
113
|
|
99
114
|
def schedule(klass, method_name, *args)
|
@@ -111,8 +126,13 @@ module BoyBand
|
|
111
126
|
def in_worker_process?
|
112
127
|
BoyBand.job_instigator.match(/^job/)
|
113
128
|
end
|
129
|
+
|
130
|
+
def current_speed
|
131
|
+
@speed
|
132
|
+
end
|
114
133
|
|
115
134
|
def perform_at(speed, *args)
|
135
|
+
@speed = speed
|
116
136
|
args_copy = [] + args
|
117
137
|
if args_copy[-1].is_a?(String) && args_copy[-1].match(/^chain::/)
|
118
138
|
set_job_chain(args_copy.pop.split(/::/, 2)[1])
|
@@ -124,6 +144,7 @@ module BoyBand
|
|
124
144
|
klass = Object.const_get(klass_string)
|
125
145
|
method_name = args_copy.shift
|
126
146
|
job_hash = Digest::MD5.hexdigest(args_copy.to_json)
|
147
|
+
Resque.redis.del("scheduled/#{klass_string}/#{method_name}/#{job_hash}")
|
127
148
|
hash = args_copy[0] if args_copy[0].is_a?(Hash)
|
128
149
|
hash ||= {'method' => method_name}
|
129
150
|
action = "#{klass_string} . #{hash['method']} (#{hash['id']})"
|
@@ -144,6 +165,7 @@ module BoyBand
|
|
144
165
|
set_job_chain("none")
|
145
166
|
BoyBand.set_job_instigator(pre_whodunnit)
|
146
167
|
clear_job(job_hash)
|
168
|
+
@speed = nil
|
147
169
|
rescue Resque::TermException
|
148
170
|
Resque.enqueue(self, *args)
|
149
171
|
end
|
@@ -166,14 +188,14 @@ module BoyBand
|
|
166
188
|
idx = Resque.size(queue)
|
167
189
|
idx.times do |i|
|
168
190
|
item = Resque.peek(queue, i)
|
169
|
-
if item['args'] && item['args'][-1].match(/^chain::/)
|
191
|
+
if item && item['args'] && item['args'][-1].match(/^chain::/)
|
170
192
|
chain = item['args'].pop
|
171
193
|
end
|
172
|
-
if item['args'] && item['args'][-1].match(/^domain::/)
|
194
|
+
if item && item['args'] && item['args'][-1].match(/^domain::/)
|
173
195
|
domain = item['args'].pop
|
174
196
|
item['domain_id'] = domain.split(/::/, 2)[1]
|
175
197
|
end
|
176
|
-
res << item
|
198
|
+
res << item if item
|
177
199
|
end
|
178
200
|
end
|
179
201
|
res
|
@@ -233,7 +255,7 @@ module BoyBand
|
|
233
255
|
list = []
|
234
256
|
idx.times do |i|
|
235
257
|
item = Resque.peek(queue, i)
|
236
|
-
if item['args'] && item['args'][2].is_a?(Hash) && item['args'][2]['method'] == method
|
258
|
+
if item && item['args'] && item['args'][2].is_a?(Hash) && item['args'][2]['method'] == method
|
237
259
|
list << item
|
238
260
|
puts item.to_json
|
239
261
|
end
|
@@ -250,8 +272,12 @@ module BoyBand
|
|
250
272
|
set_domain_id(args_copy.pop.split(/::/, 2)[1])
|
251
273
|
end
|
252
274
|
|
275
|
+
idx = queue_size(queue)
|
276
|
+
job_hash = args_copy.to_json
|
277
|
+
return true if Resque.redis.get("scheduled/#{klass.to_s}/#{method_name}/#{job_hash}") == "t"
|
278
|
+
return false if idx > 500 # big queues mustn't be searched this way
|
253
279
|
idx = Resque.size(queue)
|
254
|
-
queue_class = (queue ==
|
280
|
+
queue_class = (queue.to_s == 'slow' ? 'SlowWorker' : 'Worker')
|
255
281
|
if false
|
256
282
|
job_hash = args_copy.to_json
|
257
283
|
timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', job_hash) || "[]")
|
@@ -390,18 +416,7 @@ module BoyBand
|
|
390
416
|
end
|
391
417
|
|
392
418
|
def schedule_once(method, *args)
|
393
|
-
|
394
|
-
already_scheduled = Worker.scheduled?(self.class, :perform_action, {
|
395
|
-
'id' => id,
|
396
|
-
'method' => method,
|
397
|
-
'scheduled' => self.class.scheduled_stamp,
|
398
|
-
'arguments' => args
|
399
|
-
})
|
400
|
-
if !already_scheduled
|
401
|
-
schedule(method, *args)
|
402
|
-
else
|
403
|
-
false
|
404
|
-
end
|
419
|
+
schedule_once_for('default', method, *args)
|
405
420
|
end
|
406
421
|
|
407
422
|
def schedule_once_for(queue, method, *args)
|
@@ -438,7 +453,7 @@ module BoyBand
|
|
438
453
|
'scheduled' => self.scheduled_stamp,
|
439
454
|
'arguments' => args
|
440
455
|
}
|
441
|
-
|
456
|
+
schedule_for('default', method, *args)
|
442
457
|
end
|
443
458
|
|
444
459
|
def schedule_for(queue, method, *args)
|
@@ -452,17 +467,7 @@ module BoyBand
|
|
452
467
|
end
|
453
468
|
|
454
469
|
def schedule_once(method, *args)
|
455
|
-
|
456
|
-
already_scheduled = Worker.scheduled?(self, :perform_action, {
|
457
|
-
'method' => method,
|
458
|
-
'scheduled' => self.scheduled_stamp,
|
459
|
-
'arguments' => args
|
460
|
-
})
|
461
|
-
if !already_scheduled
|
462
|
-
schedule(method, *args)
|
463
|
-
else
|
464
|
-
false
|
465
|
-
end
|
470
|
+
schedule_once_for('default', method, *args)
|
466
471
|
end
|
467
472
|
|
468
473
|
def schedule_once_for(queue, method, *args)
|
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.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,7 @@ homepage: http://github.com/CoughDrop/boy_band
|
|
66
66
|
licenses:
|
67
67
|
- MIT
|
68
68
|
metadata: {}
|
69
|
-
post_install_message:
|
69
|
+
post_install_message:
|
70
70
|
rdoc_options: []
|
71
71
|
require_paths:
|
72
72
|
- lib
|
@@ -81,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
|
85
|
-
|
86
|
-
signing_key:
|
84
|
+
rubygems_version: 3.0.8
|
85
|
+
signing_key:
|
87
86
|
specification_version: 4
|
88
87
|
summary: BoyBand
|
89
88
|
test_files: []
|