boy_band 0.1.9 → 0.1.10

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 +4 -4
  2. data/lib/boy_band.rb +24 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b85b52259206d1051b34abeca20ad38d1cdafe605251e7d13707fca316a5191
4
- data.tar.gz: 8152e4f0b5c56c9cf51f269141297fed819ab02be65aa775be6fa4202ff7a8b8
3
+ metadata.gz: 7bb0ed487c254092a58036d84d154080993a6d82a8fc21db12e69781643fc614
4
+ data.tar.gz: a2f5dd392d8d591205cdf2b0d75b0682ef82f5f1ac7fa759f44533a057b2d847
5
5
  SHA512:
6
- metadata.gz: 906b65f3f560611b1f679b930f70073f84e111c1112bc2f6718584d627b6876ad43ab24aa3066cbd0d7ec1030f1ae9095b8b93e4405c28f1826d1e78ef9537a4
7
- data.tar.gz: 2d1bb0d2074013a46f19be979b5817e37e56d7e47cdac5dc26e10ab44bec7f67b042f6c8353804cecae2aa1304aa766d918e04537fcb983c25283e98d189afe2
6
+ metadata.gz: 21f05cb1669ac54fdc77668a0b80708092e997a832abc504872c2be5aee145b66e3bd3ff4a79b80dafb6ede62a6838d0785de9665db9e8de00f51acaf5f55fa6
7
+ data.tar.gz: 06c726f35e6c6dafe8ee6baa8ac6ec7acc37b12980b85b5f9712ec132af92912079625050cb0b9d739b3c5cc13428e2ff55dc28c3ac62519bf310cdd685a1892
@@ -39,13 +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)
44
53
  queue = queue.to_sym
45
54
  @queue = queue.to_s
46
55
  job_hash = Digest::MD5.hexdigest(args.to_json)
47
56
  note_job(job_hash)
48
- size = Resque.size(queue)
57
+ size = queue_size(queue)
49
58
  args.push("domain::#{self.domain_id}")
50
59
  chain = self.job_chain.split(/##/)
51
60
  job_id = "j#{Time.now.iso8601}_#{rand(9999)}"
@@ -80,21 +89,21 @@ module BoyBand
80
89
  end
81
90
 
82
91
  def note_job(hash)
83
- if Resque.redis
84
- timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
85
- cutoff = 6.hours.ago.to_i
86
- timestamps = timestamps.select{|ts| ts > cutoff }
87
- timestamps.push(Time.now.to_i)
88
- # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
89
- end
92
+ # if Resque.redis
93
+ # timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
94
+ # cutoff = 6.hours.ago.to_i
95
+ # timestamps = timestamps.select{|ts| ts > cutoff }
96
+ # timestamps.push(Time.now.to_i)
97
+ # # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
98
+ # end
90
99
  end
91
100
 
92
101
  def clear_job(hash)
93
- if Resque.redis
94
- timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
95
- timestamps.shift
96
- # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
97
- end
102
+ # if Resque.redis
103
+ # timestamps = JSON.parse(Resque.redis.hget('hashed_jobs', hash) || "[]")
104
+ # timestamps.shift
105
+ # # Resque.redis.hset('hashed_jobs', hash, timestamps.to_json)
106
+ # end
98
107
  end
99
108
 
100
109
  def schedule(klass, method_name, *args)
@@ -251,6 +260,8 @@ module BoyBand
251
260
  set_domain_id(args_copy.pop.split(/::/, 2)[1])
252
261
  end
253
262
 
263
+ idx = queue_size(queue)
264
+ return false if idx > 500 # big queues mustn't be searched this way
254
265
  idx = Resque.size(queue)
255
266
  queue_class = (queue == :slow ? 'SlowWorker' : 'Worker')
256
267
  if false
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.9
4
+ version: 0.1.10
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-19 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails