boy_band 0.1.7 → 0.1.8
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 +109 -4
- 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: a930be01f9c60ee6dfd4b6a31878fd1c2cba89a431396fe9f8f70d7da777b348
|
4
|
+
data.tar.gz: 58d42b0090f9fb2b8c907d0dfbdf37f832ecb398033d6d4c491215265dd5b172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9240d0607c514e5da5fc699b2e12ad9fc59abf7b41b3b2ea6a29fdd21426dc2f50bdf078a093c0b7fd6392ba26f0b86573a98ff78d6d7081512d455c64c4213c
|
7
|
+
data.tar.gz: 60b7a0dcdbc2eb3a61ceed0724d4e2db28224f2143f941aeabd5538a3c73c2ffec2c9c1b8604e03ff4b6ea83a71f32b8aec4adfff38d0f7cce688576154ed42b
|
data/lib/boy_band.rb
CHANGED
@@ -56,7 +56,7 @@ module BoyBand
|
|
56
56
|
chain.push("#{klass.to_s},#{method_name.to_s},#{args.join('+')}")
|
57
57
|
Rails.logger.warn("jobchain set, #{chain[0]} #{chain.join('##')}") if chain.length > 2
|
58
58
|
if chain.length > 5
|
59
|
-
Rails.logger.error("jobchain too
|
59
|
+
Rails.logger.error("jobchain too deep: #{chain[0]}, #{chain.length} entries")
|
60
60
|
end
|
61
61
|
job_count = Resque.redis.get("jobs_from_#{chain[0]}")
|
62
62
|
if job_count && job_count.to_i > 50
|
@@ -178,6 +178,68 @@ module BoyBand
|
|
178
178
|
end
|
179
179
|
res
|
180
180
|
end
|
181
|
+
|
182
|
+
def root_actions(queue='default')
|
183
|
+
idx = Resque.size(queue)
|
184
|
+
job_ids = {}
|
185
|
+
idx.times do |i|
|
186
|
+
item = Resque.peek(queue, i)
|
187
|
+
chain = nil
|
188
|
+
if item && item['args'] && item['args'][-1].match(/^chain::/)
|
189
|
+
chain = item['args'].pop
|
190
|
+
end
|
191
|
+
if chain
|
192
|
+
parts = chain.split(/##/)
|
193
|
+
job_ids[parts[0]] ||= [parts[1], 0, []]
|
194
|
+
job_ids[parts[0]][1] += 1
|
195
|
+
job_ids[parts[0]][2] << parts.length - 2
|
196
|
+
end
|
197
|
+
end
|
198
|
+
job_ids.each{|k, v| job_ids.delete(k) if v[1] <= 5}.length
|
199
|
+
job_ids
|
200
|
+
end
|
201
|
+
|
202
|
+
def action_types(queue='default')
|
203
|
+
idx = Resque.size(queue)
|
204
|
+
list = []
|
205
|
+
idx.times do |i|
|
206
|
+
item = Resque.peek(queue, i)
|
207
|
+
chain = nil
|
208
|
+
if item && item['args'] && item['args'][-1].match(/^chain::/)
|
209
|
+
chain = item['args'].pop
|
210
|
+
end
|
211
|
+
if chain
|
212
|
+
match = chain.scan(/##/)
|
213
|
+
if match && match.length == 1
|
214
|
+
item['root'] = true
|
215
|
+
list << item
|
216
|
+
elsif match && match.length > 1
|
217
|
+
list << item
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
count = {'root' => {}, 'non_root' => {}}
|
222
|
+
list.each do |item|
|
223
|
+
key = "#{item['args'][0]}::#{item['args'][2].is_a?(Hash) ? item['args'][2]['method'] : item['args'][1]}"
|
224
|
+
count[item['root'] ? 'root' : 'non_root'][key] ||= 0
|
225
|
+
count[item['root'] ? 'root' : 'non_root'][key] += 1
|
226
|
+
end.length
|
227
|
+
count
|
228
|
+
end
|
229
|
+
|
230
|
+
def find_actions(method)
|
231
|
+
queue = 'default'
|
232
|
+
idx = Resque.size(queue)
|
233
|
+
list = []
|
234
|
+
idx.times do |i|
|
235
|
+
item = Resque.peek(queue, i)
|
236
|
+
if item['args'] && item['args'][2].is_a?(Hash) && item['args'][2]['method'] == method
|
237
|
+
list << item
|
238
|
+
puts item.to_json
|
239
|
+
end
|
240
|
+
end
|
241
|
+
list
|
242
|
+
end
|
181
243
|
|
182
244
|
def scheduled_for?(queue, klass, method_name, *args)
|
183
245
|
args_copy = [] + args
|
@@ -312,6 +374,10 @@ module BoyBand
|
|
312
374
|
|
313
375
|
module AsyncInstanceMethods
|
314
376
|
def schedule(method, *args)
|
377
|
+
schedule_for('default', method, *args)
|
378
|
+
end
|
379
|
+
|
380
|
+
def schedule_for(queue, method, *args)
|
315
381
|
return nil unless method
|
316
382
|
id = self.id
|
317
383
|
settings = {
|
@@ -320,9 +386,9 @@ module BoyBand
|
|
320
386
|
'scheduled' => self.class.scheduled_stamp,
|
321
387
|
'arguments' => args
|
322
388
|
}
|
323
|
-
Worker.
|
389
|
+
Worker.schedule_for(queue, self.class, :perform_action, settings)
|
324
390
|
end
|
325
|
-
|
391
|
+
|
326
392
|
def schedule_once(method, *args)
|
327
393
|
return nil unless method && id
|
328
394
|
already_scheduled = Worker.scheduled?(self.class, :perform_action, {
|
@@ -338,6 +404,21 @@ module BoyBand
|
|
338
404
|
end
|
339
405
|
end
|
340
406
|
|
407
|
+
def schedule_once_for(queue, method, *args)
|
408
|
+
return nil unless method && id
|
409
|
+
already_scheduled = Worker.scheduled_for?(queue, self.class, :perform_action, {
|
410
|
+
'id' => id,
|
411
|
+
'method' => method,
|
412
|
+
'scheduled' => self.class.scheduled_stamp,
|
413
|
+
'arguments' => args
|
414
|
+
})
|
415
|
+
if !already_scheduled
|
416
|
+
schedule_for(queue, method, *args)
|
417
|
+
else
|
418
|
+
false
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
341
422
|
def self.included(base)
|
342
423
|
base.define_singleton_method(:included) do |klass|
|
343
424
|
klass.cattr_accessor :last_scheduled_stamp
|
@@ -360,6 +441,16 @@ module BoyBand
|
|
360
441
|
Worker.schedule(self, :perform_action, settings)
|
361
442
|
end
|
362
443
|
|
444
|
+
def schedule_for(queue, method, *args)
|
445
|
+
return nil unless method
|
446
|
+
settings = {
|
447
|
+
'method' => method,
|
448
|
+
'scheduled' => self.scheduled_stamp,
|
449
|
+
'arguments' => args
|
450
|
+
}
|
451
|
+
Worker.schedule_for(queue, self, :perform_action, settings)
|
452
|
+
end
|
453
|
+
|
363
454
|
def schedule_once(method, *args)
|
364
455
|
return nil unless method
|
365
456
|
already_scheduled = Worker.scheduled?(self, :perform_action, {
|
@@ -373,7 +464,21 @@ module BoyBand
|
|
373
464
|
false
|
374
465
|
end
|
375
466
|
end
|
376
|
-
|
467
|
+
|
468
|
+
def schedule_once_for(queue, method, *args)
|
469
|
+
return nil unless method
|
470
|
+
already_scheduled = Worker.scheduled_for?(queue, self, :perform_action, {
|
471
|
+
'method' => method,
|
472
|
+
'scheduled' => self.scheduled_stamp,
|
473
|
+
'arguments' => args
|
474
|
+
})
|
475
|
+
if !already_scheduled
|
476
|
+
schedule_for(queue, method, *args)
|
477
|
+
else
|
478
|
+
false
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
377
482
|
def perform_action(settings)
|
378
483
|
obj = self
|
379
484
|
if settings['id']
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|