boy_band 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/boy_band.rb +29 -3
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5e03c7c42074aeaff0bd494ba78eb3cffbb094e8
4
- data.tar.gz: 409baedbbf6bdc1b9e07e8086e7ad71d9fde4243
2
+ SHA256:
3
+ metadata.gz: 2247a143d94db73ccc3883573efe8f2ee6e8014e98be1579fe5a4c502b9693fe
4
+ data.tar.gz: fb69313dc99cd537b181c504bab6063cea44f9a5a48dd426a22efacf2b24421d
5
5
  SHA512:
6
- metadata.gz: 7574bd22d22361781f54129ff59c4cf4c1cc83947e8126c5e7610148664ef453668a02d709c493d7ef3405307f0759b57adc8e4db496e0f3524ba4ecc31fa3a5
7
- data.tar.gz: e29e8da9415ab4af0c4fe36882ad9ab63651acd90446b225fb93bec37642b5ce52dad7106416e0ef892d06fc3dd62501a9402cde028b9556e47c9039c462666f
6
+ metadata.gz: b6ff5deeb6e38613fbc6fa2efa57b953c5dd676399fee4d3304f4460610f7bb736a7e1e6636687d2673a9c6504a63a78ad539e43b4357b5cb2e73120f1435f12
7
+ data.tar.gz: 83f7cfddacab2aa2937b7b5ab5400bf911f242b243eb137e84f5db83b263164bbb28ed789691607b90ad63a215dc4eadd2513c0b422df9468831009105ad53ab
data/lib/boy_band.rb CHANGED
@@ -21,12 +21,22 @@ module BoyBand
21
21
  def thread_id
22
22
  "#{Process.pid}_#{Thread.current.object_id}"
23
23
  end
24
+
25
+ def domain_id
26
+ @@domain_id ||= "default"
27
+ @@domain_id
28
+ end
29
+
30
+ def set_domain_id(val)
31
+ @@domain_id = val
32
+ end
24
33
 
25
34
  def schedule_for(queue, klass, method_name, *args)
26
35
  @queue = queue.to_s
27
36
  job_hash = Digest::MD5.hexdigest(args.to_json)
28
37
  note_job(job_hash)
29
38
  size = Resque.size(queue)
39
+ args.push("domain::#{self.domain_id}")
30
40
  if queue == :slow
31
41
  Resque.enqueue(SlowWorker, klass.to_s, method_name, *args)
32
42
  if size > 1000 && !Resque.redis.get("queue_warning_#{queue}")
@@ -78,6 +88,9 @@ module BoyBand
78
88
 
79
89
  def perform_at(speed, *args)
80
90
  args_copy = [] + args
91
+ if args[-1].is_a?(String) && args[-1].match(/^domain::/)
92
+ set_domain_id(args_copy.pop.split(/::/, 2)[1])
93
+ end
81
94
  klass_string = args_copy.shift
82
95
  klass = Object.const_get(klass_string)
83
96
  method_name = args_copy.shift
@@ -122,17 +135,27 @@ module BoyBand
122
135
  queues.each do |queue|
123
136
  idx = Resque.size(queue)
124
137
  idx.times do |i|
125
- res << Resque.peek(queue, i)
138
+ item = Resque.peek(queue, i)
139
+ if item['args'] && item['args'][-1].match(/^domain::/)
140
+ domain = item['args'].pop
141
+ item['domain_id'] = domain.split(/::/, 2)[1]
142
+ end
143
+ res << item
126
144
  end
127
145
  end
128
146
  res
129
147
  end
130
148
 
131
149
  def scheduled_for?(queue, klass, method_name, *args)
150
+ args_copy = [] + args
151
+ if args[-1].is_a?(String) && args[-1].match(/^domain::/)
152
+ set_domain_id(args_copy.pop.split(/::/, 2)[1])
153
+ end
154
+
132
155
  idx = Resque.size(queue)
133
156
  queue_class = (queue == :slow ? 'SlowWorker' : 'Worker')
134
157
  if false
135
- job_hash = args.to_json
158
+ job_hash = args_copy.to_json
136
159
  timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', job_hash) || "[]")
137
160
  cutoff = 6.hours.ago.to_i
138
161
  return timestamps.select{|ts| ts > cutoff }.length > 0
@@ -143,15 +166,18 @@ module BoyBand
143
166
  start += items.length > 0 ? items.length : 1
144
167
  items.each do |schedule|
145
168
  if schedule && schedule['class'] == queue_class && schedule['args'][0] == klass.to_s && schedule['args'][1] == method_name.to_s
146
- a1 = args
169
+ a1 = args_copy
147
170
  if a1.length == 1 && a1[0].is_a?(Hash)
148
171
  a1 = [a1[0].dup]
149
172
  a1[0].delete('scheduled')
173
+ a1[0].delete('domain_id')
150
174
  end
151
175
  a2 = schedule['args'][2..-1]
176
+ a2.pop if a2.length == 2 && a2[1].is_a?(String) && a2[1].match(/^domain::/)
152
177
  if a2.length == 1 && a2[0].is_a?(Hash)
153
178
  a2 = [a2[0].dup]
154
179
  a2[0].delete('scheduled')
180
+ a2[0].delete('domain_id')
155
181
  end
156
182
  if a1.to_json == a2.to_json
157
183
  return true
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-17 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.5.2
85
+ rubygems_version: 2.7.7
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: BoyBand