hirefire-resource 0.5.0 → 0.6.0
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/hirefire-resource.gemspec +1 -1
- data/lib/hirefire/macro/sidekiq.rb +53 -9
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3707ebd2fc7528f274027a9089e6c9a68f8371f23ddcf83bb367ebe594972667
|
|
4
|
+
data.tar.gz: ec772d13937e655834c9863380c8c651a9d2847a0598841c6763b61b21cc2568
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e4930d3819da8e2c3f6e5903e12683a2eba0c4514f07ab0eb9ed65f80d0a71ebf6f2949e1445ca5b6165c477a4e0aa87e2c994f21afe37bddfbe69e1cde76f
|
|
7
|
+
data.tar.gz: f7f1395eb1d880ec10a5344c409216017156d2ae977157968fe99de800ba594ae2621ed44173becf809b4872efbc256e175761d3c7147369d05630a2fd90dddf
|
data/hirefire-resource.gemspec
CHANGED
|
@@ -28,9 +28,44 @@ module HireFire
|
|
|
28
28
|
options = {}
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
queues
|
|
32
|
-
|
|
31
|
+
queues.map!(&:to_s)
|
|
32
|
+
all_queues = ::Sidekiq::Queue.all.map(&:name)
|
|
33
|
+
queues = all_queues if queues.empty?
|
|
33
34
|
|
|
35
|
+
if fast_lookup_capable?(queues, all_queues)
|
|
36
|
+
fast_lookup(options)
|
|
37
|
+
else
|
|
38
|
+
dynamic_lookup(queues, options)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def fast_lookup_capable?(queues, all_queues)
|
|
45
|
+
# When no queue names are provided (or all of them are), we know we
|
|
46
|
+
# can peform much faster counts using Sidekiq::Stats and Redis
|
|
47
|
+
queues.sort == all_queues.sort
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def fast_lookup(options)
|
|
51
|
+
stats = ::Sidekiq::Stats.new
|
|
52
|
+
|
|
53
|
+
in_queues = stats.enqueued
|
|
54
|
+
|
|
55
|
+
if !options[:skip_scheduled]
|
|
56
|
+
in_schedule = ::Sidekiq.redis { |c| c.zcount('schedule', '-inf', Time.now.to_f) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if !options[:skip_retries]
|
|
60
|
+
in_retry = ::Sidekiq.redis { |c| c.zcount('retry', '-inf', Time.now.to_f) }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
in_progress = stats.workers_size
|
|
64
|
+
|
|
65
|
+
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def dynamic_lookup(queues, options)
|
|
34
69
|
in_queues = queues.inject(0) do |memo, name|
|
|
35
70
|
memo += ::Sidekiq::Queue.new(name).size
|
|
36
71
|
memo
|
|
@@ -38,25 +73,34 @@ module HireFire
|
|
|
38
73
|
|
|
39
74
|
if !options[:skip_scheduled]
|
|
40
75
|
max = options[:max_scheduled]
|
|
76
|
+
|
|
77
|
+
# For potentially long-running loops, compare all jobs against
|
|
78
|
+
# time when the set snapshot was taken to avoid incorrect counts.
|
|
79
|
+
now = Time.now
|
|
80
|
+
|
|
41
81
|
in_schedule = ::Sidekiq::ScheduledSet.new.inject(0) do |memo, job|
|
|
42
|
-
memo += 1 if queues.include?(job["queue"]) && job.at <=
|
|
82
|
+
memo += 1 if queues.include?(job["queue"]) && job.at <= now
|
|
43
83
|
break memo if max && memo >= max
|
|
44
84
|
memo
|
|
45
85
|
end
|
|
46
86
|
end
|
|
47
87
|
|
|
48
88
|
if !options[:skip_retries]
|
|
89
|
+
now = Time.now
|
|
90
|
+
|
|
49
91
|
in_retry = ::Sidekiq::RetrySet.new.inject(0) do |memo, job|
|
|
50
|
-
memo += 1 if queues.include?(job["queue"]) && job.at <=
|
|
92
|
+
memo += 1 if queues.include?(job["queue"]) && job.at <= now
|
|
51
93
|
memo
|
|
52
94
|
end
|
|
53
95
|
end
|
|
54
96
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
97
|
+
now = Time.now.to_i
|
|
98
|
+
|
|
99
|
+
# Objects yielded to Workers#each:
|
|
100
|
+
# https://github.com/mperham/sidekiq/blob/305ab8eedc362325da2e218b2a0e20e510668a42/lib/sidekiq/api.rb#L912
|
|
101
|
+
in_progress = ::Sidekiq::Workers.new.select do |key, tid, job|
|
|
102
|
+
queues.include?(job['queue']) && job['run_at'] <= now
|
|
103
|
+
end.size
|
|
60
104
|
|
|
61
105
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
|
62
106
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hirefire-resource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael van Rooijen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Load- and schedule-based scaling for web- and worker dynos
|
|
14
14
|
email: michael@hirefire.io
|
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
57
|
version: '0'
|
|
58
58
|
requirements: []
|
|
59
59
|
rubyforge_project:
|
|
60
|
-
rubygems_version: 2.7.
|
|
60
|
+
rubygems_version: 2.7.7
|
|
61
61
|
signing_key:
|
|
62
62
|
specification_version: 4
|
|
63
63
|
summary: Autoscaling for your Heroku dynos
|