hirefire-resource 0.8.0 → 0.10.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/.github/workflows/main.yml +16 -0
- data/CHANGELOG.md +21 -1
- data/Gemfile +10 -0
- data/Gemfile.lock +49 -0
- data/README.md +7 -3
- data/Rakefile +3 -0
- data/hirefire-resource.gemspec +14 -18
- data/lib/hirefire/macro/bunny.rb +14 -19
- data/lib/hirefire/macro/delayed_job.rb +11 -12
- data/lib/hirefire/macro/good_job.rb +3 -2
- data/lib/hirefire/macro/qc.rb +1 -2
- data/lib/hirefire/macro/qu.rb +5 -3
- data/lib/hirefire/macro/que.rb +32 -13
- data/lib/hirefire/macro/resque.rb +1 -1
- data/lib/hirefire/macro/sidekiq.rb +28 -14
- data/lib/hirefire/middleware.rb +10 -11
- data/lib/hirefire/railtie.rb +1 -1
- data/lib/hirefire/resource.rb +3 -3
- data/lib/hirefire-resource.rb +1 -1
- metadata +7 -9
- data/bin/hirefire +0 -4
- data/bin/hirefireapp +0 -5
- data/lib/hirefire/cli.rb +0 -48
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: affa2055a22d9ebc019b20ddace8e5fe042bd7c04115735d88fac5710458eb1d
|
|
4
|
+
data.tar.gz: d5b2aa9fade2670ca74f1af8e3ed3ba76cfb0b520d0794077f1e0e0bc5e8459b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f3455375d6259f6d1142056af6c3285fcbfe6aafeac6e0d92778b49e9a2818378edebe6d68f6cecf74522e11b78932361f69c5fe4328ca3768937a42a7541ed
|
|
7
|
+
data.tar.gz: aad73cc64b02064a4b8d4bd451f578415939300dcaeed6345315bcff99268943c70d774c820d591b7deaa6afd60edeee1c2fd64928847078111f4ccd8c6fafb9
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v2
|
|
10
|
+
- name: Set up Ruby
|
|
11
|
+
uses: ruby/setup-ruby@v1
|
|
12
|
+
with:
|
|
13
|
+
ruby-version: 3.0.2
|
|
14
|
+
bundler-cache: true
|
|
15
|
+
- name: Run standardrb
|
|
16
|
+
run: bundle exec rake standard
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
## v0.
|
|
1
|
+
## v0.10.0
|
|
2
|
+
|
|
3
|
+
* Support Latency (Sidekiq)
|
|
4
|
+
* Rename the "quantity" property to "value" in JSON response ("quantity" is still supported)
|
|
5
|
+
|
|
6
|
+
## v0.9.1
|
|
7
|
+
|
|
8
|
+
* Support GoodJob > 2.2 where Job class is renamed to Execution
|
|
9
|
+
|
|
10
|
+
## v0.9.0
|
|
11
|
+
|
|
12
|
+
* Add `skip_working` to Sidekiq macro
|
|
13
|
+
* Use separate queries for Que 0.x and 1.x
|
|
14
|
+
* Remove `# encoding: utf-8` magic comments
|
|
15
|
+
* Add `# frozen_string_literal: true` magic comments
|
|
16
|
+
|
|
17
|
+
## v0.8.1
|
|
18
|
+
|
|
19
|
+
* Correct GoodJob macro to not count finished jobs.
|
|
20
|
+
|
|
21
|
+
## v0.8.0
|
|
2
22
|
|
|
3
23
|
* Add GoodJob macro for `good_job` adapter. https://github.com/bensheldon/good_job
|
|
4
24
|
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
hirefire-resource (0.9.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.2)
|
|
10
|
+
parallel (1.21.0)
|
|
11
|
+
parser (3.0.3.2)
|
|
12
|
+
ast (~> 2.4.1)
|
|
13
|
+
rainbow (3.0.0)
|
|
14
|
+
rake (13.0.6)
|
|
15
|
+
regexp_parser (2.2.0)
|
|
16
|
+
rexml (3.2.5)
|
|
17
|
+
rubocop (1.23.0)
|
|
18
|
+
parallel (~> 1.10)
|
|
19
|
+
parser (>= 3.0.0.0)
|
|
20
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
21
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
22
|
+
rexml
|
|
23
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
|
24
|
+
ruby-progressbar (~> 1.7)
|
|
25
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
26
|
+
rubocop-ast (1.15.0)
|
|
27
|
+
parser (>= 3.0.1.1)
|
|
28
|
+
rubocop-performance (1.12.0)
|
|
29
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
30
|
+
rubocop-ast (>= 0.4.0)
|
|
31
|
+
ruby-progressbar (1.11.0)
|
|
32
|
+
standard (1.5.0)
|
|
33
|
+
rubocop (= 1.23.0)
|
|
34
|
+
rubocop-performance (= 1.12.0)
|
|
35
|
+
standardrb (1.0.0)
|
|
36
|
+
standard
|
|
37
|
+
unicode-display_width (2.1.0)
|
|
38
|
+
|
|
39
|
+
PLATFORMS
|
|
40
|
+
x86_64-darwin-20
|
|
41
|
+
x86_64-linux
|
|
42
|
+
|
|
43
|
+
DEPENDENCIES
|
|
44
|
+
hirefire-resource!
|
|
45
|
+
rake
|
|
46
|
+
standardrb
|
|
47
|
+
|
|
48
|
+
BUNDLED WITH
|
|
49
|
+
2.2.24
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
## [HireFire]
|
|
1
|
+
## [HireFire] - Autoscaling for [Heroku]
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Response times, queue times, job queues, load and schedule-based autoscaling for web and worker dynos on [Heroku].
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -84,8 +84,12 @@ dj_worker: QUEUES=encode,compress bundle exec rake jobs:work
|
|
|
84
84
|
|
|
85
85
|
Now that HireFire will scale both of the these dyno types based on their individual queue sizes. To customize how they scale, log in to the HireFire web interface.
|
|
86
86
|
|
|
87
|
-
Visit the [official website]
|
|
87
|
+
Visit the [official website] for more information!
|
|
88
88
|
|
|
89
89
|
### License
|
|
90
90
|
|
|
91
91
|
hirefire-resource is released under the Apache 2.0 license. See LICENSE.
|
|
92
|
+
|
|
93
|
+
[HireFire]: https://www.hirefire.io/
|
|
94
|
+
[official website]: https://www.hirefire.io/
|
|
95
|
+
[Heroku]: https://www.heroku.com/
|
data/Rakefile
CHANGED
data/hirefire-resource.gemspec
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
gem.licenses = ["Apache License"]
|
|
13
|
-
gem.metadata = {
|
|
1
|
+
Gem::Specification.new do |spec|
|
|
2
|
+
spec.name = "hirefire-resource"
|
|
3
|
+
spec.version = "0.10.0"
|
|
4
|
+
spec.platform = Gem::Platform::RUBY
|
|
5
|
+
spec.authors = "Michael van Rooijen"
|
|
6
|
+
spec.email = "michael@hirefire.io"
|
|
7
|
+
spec.homepage = "https://www.hirefire.io"
|
|
8
|
+
spec.summary = "Autoscaling for your Heroku dynos"
|
|
9
|
+
spec.description = "Load- and schedule-based scaling for web- and worker dynos"
|
|
10
|
+
spec.licenses = ["Apache License"]
|
|
11
|
+
spec.metadata = {
|
|
14
12
|
"homepage_uri" => "https://www.hirefire.io",
|
|
15
13
|
"changelog_uri" => "https://github.com/hirefire/hirefire-resource/blob/master/CHANGELOG.md",
|
|
16
14
|
"source_code_uri" => "https://github.com/hirefire/hirefire-resource/",
|
|
17
|
-
"bug_tracker_uri" => "https://github.com/hirefire/hirefire-resource/issues"
|
|
15
|
+
"bug_tracker_uri" => "https://github.com/hirefire/hirefire-resource/issues"
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
gem.executables = ["hirefire", "hirefireapp"]
|
|
22
|
-
gem.require_path = "lib"
|
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
|
18
|
+
spec.require_path = "lib"
|
|
23
19
|
end
|
data/lib/hirefire/macro/bunny.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
@@ -27,10 +27,10 @@ module HireFire
|
|
|
27
27
|
|
|
28
28
|
queues.flatten!
|
|
29
29
|
|
|
30
|
-
if queues.last.is_a?(Hash)
|
|
31
|
-
|
|
30
|
+
options = if queues.last.is_a?(Hash)
|
|
31
|
+
queues.pop
|
|
32
32
|
else
|
|
33
|
-
|
|
33
|
+
{}
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
if options[:durable].nil?
|
|
@@ -43,38 +43,33 @@ module HireFire
|
|
|
43
43
|
channel = nil
|
|
44
44
|
begin
|
|
45
45
|
channel = connection.create_channel
|
|
46
|
-
|
|
46
|
+
count_messages(channel, queues, options)
|
|
47
47
|
ensure
|
|
48
|
-
|
|
49
|
-
channel.close
|
|
50
|
-
end
|
|
48
|
+
channel&.close
|
|
51
49
|
end
|
|
52
50
|
elsif options[:amqp_url]
|
|
53
51
|
connection = ::Bunny.new(options[:amqp_url])
|
|
54
52
|
begin
|
|
55
53
|
connection.start
|
|
56
54
|
channel = connection.create_channel
|
|
57
|
-
|
|
55
|
+
count_messages(channel, queues, options)
|
|
58
56
|
ensure
|
|
59
|
-
|
|
60
|
-
channel.close
|
|
61
|
-
end
|
|
62
|
-
|
|
57
|
+
channel&.close
|
|
63
58
|
connection.close
|
|
64
59
|
end
|
|
65
60
|
else
|
|
66
|
-
raise %
|
|
67
|
-
|
|
61
|
+
raise %(Must pass in :connection => rabbitmq_connection or :amqp_url => url\n) +
|
|
62
|
+
%{For example: HireFire::Macro::Bunny.queue("queue1", :connection => rabbitmq_connection}
|
|
68
63
|
end
|
|
69
64
|
end
|
|
70
65
|
|
|
71
66
|
def count_messages(channel, queue_names, options)
|
|
72
67
|
queue_names.inject(0) do |sum, queue_name|
|
|
73
|
-
if options.key?(:'x-max-priority')
|
|
74
|
-
|
|
75
|
-
:
|
|
68
|
+
queue = if options.key?(:'x-max-priority')
|
|
69
|
+
channel.queue(queue_name, durable: options[:durable],
|
|
70
|
+
arguments: {"x-max-priority" => options[:'x-max-priority']})
|
|
76
71
|
else
|
|
77
|
-
|
|
72
|
+
channel.queue(queue_name, durable: options[:durable])
|
|
78
73
|
end
|
|
79
74
|
sum + queue.message_count
|
|
80
75
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
@@ -35,26 +35,26 @@ module HireFire
|
|
|
35
35
|
def queue(*queues)
|
|
36
36
|
queues.flatten!
|
|
37
37
|
|
|
38
|
-
if queues.last.is_a?(Hash)
|
|
39
|
-
|
|
38
|
+
options = if queues.last.is_a?(Hash)
|
|
39
|
+
queues.pop
|
|
40
40
|
else
|
|
41
|
-
|
|
41
|
+
{}
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
case options[:mapper]
|
|
45
45
|
when :active_record
|
|
46
46
|
c = ::Delayed::Job
|
|
47
|
-
c = c.where(:
|
|
47
|
+
c = c.where(failed_at: nil)
|
|
48
48
|
c = c.where("run_at <= ?", Time.now.utc)
|
|
49
49
|
c = c.where("priority >= ?", options[:min_priority]) if options.key?(:min_priority)
|
|
50
50
|
c = c.where("priority <= ?", options[:max_priority]) if options.key?(:max_priority)
|
|
51
|
-
c = c.where(:
|
|
51
|
+
c = c.where(queue: queues) unless queues.empty?
|
|
52
52
|
c.count.tap { ActiveRecord::Base.clear_active_connections! }
|
|
53
53
|
when :active_record_2
|
|
54
54
|
c = ::Delayed::Job
|
|
55
|
-
c = c.scoped(:
|
|
56
|
-
c = c.scoped(:
|
|
57
|
-
c = c.scoped(:
|
|
55
|
+
c = c.scoped(conditions: ["run_at <= ? AND failed_at is NULL", Time.now.utc])
|
|
56
|
+
c = c.scoped(conditions: ["priority >= ?", options[:min_priority]]) if options.key?(:min_priority)
|
|
57
|
+
c = c.scoped(conditions: ["priority <= ?", options[:max_priority]]) if options.key?(:max_priority)
|
|
58
58
|
# There is no queue column in delayed_job <= 2.x
|
|
59
59
|
c.count.tap do
|
|
60
60
|
if ActiveRecord::Base.respond_to?(:clear_active_connections!)
|
|
@@ -63,14 +63,14 @@ module HireFire
|
|
|
63
63
|
end
|
|
64
64
|
when :mongoid
|
|
65
65
|
c = ::Delayed::Job
|
|
66
|
-
c = c.where(:
|
|
66
|
+
c = c.where(failed_at: nil)
|
|
67
67
|
c = c.where(:run_at.lte => Time.now.utc)
|
|
68
68
|
c = c.where(:priority.gte => options[:min_priority]) if options.key?(:min_priority)
|
|
69
69
|
c = c.where(:priority.lte => options[:max_priority]) if options.key?(:max_priority)
|
|
70
70
|
c = c.where(:queue.in => queues) unless queues.empty?
|
|
71
71
|
c.count
|
|
72
72
|
else
|
|
73
|
-
raise %
|
|
73
|
+
raise %(Must pass in :mapper => :active_record or :mapper => :mongoid\n) +
|
|
74
74
|
%{For example: HireFire::Macro::Delayed::Job.queue("worker", :mapper => :active_record)}
|
|
75
75
|
end
|
|
76
76
|
end
|
|
@@ -78,4 +78,3 @@ module HireFire
|
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
end
|
|
81
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
@@ -16,7 +16,8 @@ module HireFire
|
|
|
16
16
|
# @return [Integer] the number of jobs in the queue(s).
|
|
17
17
|
#
|
|
18
18
|
def queue(*queues)
|
|
19
|
-
|
|
19
|
+
base_class = defined?(::GoodJob::Execution) ? ::GoodJob::Execution : ::GoodJob::Job
|
|
20
|
+
scope = base_class.only_scheduled.unfinished
|
|
20
21
|
scope = scope.where(queue_name: queues) if queues.any?
|
|
21
22
|
scope.count
|
|
22
23
|
end
|
data/lib/hirefire/macro/qc.rb
CHANGED
data/lib/hirefire/macro/qu.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
@@ -17,9 +17,11 @@ module HireFire
|
|
|
17
17
|
#
|
|
18
18
|
def queue(*queues)
|
|
19
19
|
queues = ::Qu.backend.queues if queues.empty?
|
|
20
|
-
queues.flatten.inject(0) { |memo, queue|
|
|
20
|
+
queues.flatten.inject(0) { |memo, queue|
|
|
21
|
+
memo += ::Qu.backend.length(queue)
|
|
22
|
+
memo
|
|
23
|
+
}
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
end
|
|
24
27
|
end
|
|
25
|
-
|
data/lib/hirefire/macro/que.rb
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
5
5
|
module Que
|
|
6
|
-
QUERY = %{
|
|
7
|
-
SELECT count(*) AS total
|
|
8
|
-
FROM que_jobs WHERE run_at < now() }.freeze
|
|
9
|
-
|
|
10
6
|
extend self
|
|
11
7
|
|
|
12
8
|
# Queries the PostgreSQL database through Que in order to
|
|
@@ -20,17 +16,40 @@ FROM que_jobs WHERE run_at < now() }.freeze
|
|
|
20
16
|
# @return [Integer] the number of jobs in the queue(s).
|
|
21
17
|
#
|
|
22
18
|
def queue(*queues)
|
|
23
|
-
query =
|
|
24
|
-
when queues.none? then QUERY
|
|
25
|
-
when queues.one? then "#{QUERY} AND queue = '#{queues.first}'"
|
|
26
|
-
else
|
|
27
|
-
queue_names = queues.map { |queue| "'#{queue}'" }.join(', ')
|
|
28
|
-
%Q{#{QUERY} AND queue IN (#{queue_names})}
|
|
29
|
-
end
|
|
30
|
-
|
|
19
|
+
query = queues.empty? && base_query || base_query + " AND queue IN (#{names(queues)})"
|
|
31
20
|
results = ::Que.execute(query).first
|
|
32
21
|
(results[:total] || results["total"]).to_i
|
|
33
22
|
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def base_query
|
|
27
|
+
return QUE_V0_QUERY if defined?(::Que::Version)
|
|
28
|
+
return QUE_V1_QUERY if defined?(::Que::VERSION)
|
|
29
|
+
raise "Couldn't find Que version"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def names(queues)
|
|
33
|
+
queues.map { |queue| "'#{queue}'" }.join(",")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def query_const(query)
|
|
37
|
+
query.gsub(/\s+/, " ").strip.freeze
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
QUE_V0_QUERY = query_const(<<-QUERY)
|
|
41
|
+
SELECT COUNT(*) AS total
|
|
42
|
+
FROM que_jobs
|
|
43
|
+
WHERE run_at < NOW()
|
|
44
|
+
QUERY
|
|
45
|
+
|
|
46
|
+
QUE_V1_QUERY = query_const(<<-QUERY)
|
|
47
|
+
SELECT COUNT(*) AS total
|
|
48
|
+
FROM que_jobs
|
|
49
|
+
WHERE finished_at IS NULL
|
|
50
|
+
AND expired_at IS NULL
|
|
51
|
+
AND run_at <= NOW()
|
|
52
|
+
QUERY
|
|
34
53
|
end
|
|
35
54
|
end
|
|
36
55
|
end
|
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Macro
|
|
5
5
|
module Sidekiq
|
|
6
6
|
extend self
|
|
7
7
|
|
|
8
|
+
# The latency in seconds for the provided queue.
|
|
9
|
+
#
|
|
10
|
+
# @example Sidekiq Queue Latency Macro Usage
|
|
11
|
+
# HireFire::Macro::Sidekiq.queue # default queue
|
|
12
|
+
# HireFire::Macro::Sidekiq.queue("email") # email queue
|
|
13
|
+
#
|
|
14
|
+
def latency(queue = "default")
|
|
15
|
+
::Sidekiq::Queue.new(queue).latency
|
|
16
|
+
end
|
|
17
|
+
|
|
8
18
|
# Counts the amount of jobs in the (provided) Sidekiq queue(s).
|
|
9
19
|
#
|
|
10
|
-
# @example Sidekiq Macro Usage
|
|
20
|
+
# @example Sidekiq Queue Size Macro Usage
|
|
11
21
|
# HireFire::Macro::Sidekiq.queue # all queues
|
|
12
22
|
# HireFire::Macro::Sidekiq.queue("email") # only email queue
|
|
13
23
|
# HireFire::Macro::Sidekiq.queue("audio", "video") # audio and video queues
|
|
14
24
|
# HireFire::Macro::Sidekiq.queue("email", skip_scheduled: true) # only email, will not count scheduled queue
|
|
15
25
|
# HireFire::Macro::Sidekiq.queue("audio", skip_retries: true) # only audio, will not count the retries queue
|
|
26
|
+
# HireFire::Macro::Sidekiq.queue("audio", skip_working: true) # only audio, will not count already queued
|
|
16
27
|
#
|
|
17
28
|
# @param [Array] queues provide one or more queue names, or none for "all".
|
|
18
29
|
# @return [Integer] the number of jobs in the queue(s).
|
|
@@ -22,10 +33,10 @@ module HireFire
|
|
|
22
33
|
|
|
23
34
|
queues.flatten!
|
|
24
35
|
|
|
25
|
-
if queues.last.is_a?(Hash)
|
|
26
|
-
|
|
36
|
+
options = if queues.last.is_a?(Hash)
|
|
37
|
+
queues.pop
|
|
27
38
|
else
|
|
28
|
-
|
|
39
|
+
{}
|
|
29
40
|
end
|
|
30
41
|
|
|
31
42
|
queues.map!(&:to_s)
|
|
@@ -53,14 +64,16 @@ module HireFire
|
|
|
53
64
|
in_queues = stats.enqueued
|
|
54
65
|
|
|
55
66
|
if !options[:skip_scheduled]
|
|
56
|
-
in_schedule = ::Sidekiq.redis { |c| c.zcount(
|
|
67
|
+
in_schedule = ::Sidekiq.redis { |c| c.zcount("schedule", "-inf", Time.now.to_f) }
|
|
57
68
|
end
|
|
58
69
|
|
|
59
70
|
if !options[:skip_retries]
|
|
60
|
-
in_retry = ::Sidekiq.redis { |c| c.zcount(
|
|
71
|
+
in_retry = ::Sidekiq.redis { |c| c.zcount("retry", "-inf", Time.now.to_f) }
|
|
61
72
|
end
|
|
62
73
|
|
|
63
|
-
|
|
74
|
+
if !options[:skip_working]
|
|
75
|
+
in_progress = stats.workers_size
|
|
76
|
+
end
|
|
64
77
|
|
|
65
78
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
|
66
79
|
end
|
|
@@ -96,15 +109,16 @@ module HireFire
|
|
|
96
109
|
|
|
97
110
|
now = Time.now.to_i
|
|
98
111
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
if !options[:skip_working]
|
|
113
|
+
# Objects yielded to Workers#each:
|
|
114
|
+
# https://github.com/mperham/sidekiq/blob/305ab8eedc362325da2e218b2a0e20e510668a42/lib/sidekiq/api.rb#L912
|
|
115
|
+
in_progress = ::Sidekiq::Workers.new.count do |key, tid, job|
|
|
116
|
+
queues.include?(job["queue"]) && job["run_at"] <= now
|
|
117
|
+
end
|
|
118
|
+
end
|
|
104
119
|
|
|
105
120
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
|
106
121
|
end
|
|
107
122
|
end
|
|
108
123
|
end
|
|
109
124
|
end
|
|
110
|
-
|
data/lib/hirefire/middleware.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
class Middleware
|
|
5
|
-
|
|
6
5
|
# Initializes HireFire::Middleware.
|
|
7
6
|
#
|
|
8
7
|
# @param [Proc] app call with `env` to continue down the middleware stack.
|
|
9
8
|
#
|
|
10
9
|
def initialize(app)
|
|
11
|
-
@app
|
|
12
|
-
@token
|
|
10
|
+
@app = app
|
|
11
|
+
@token = ENV["HIREFIRE_TOKEN"]
|
|
13
12
|
@path_prefix = get_path_prefix
|
|
14
13
|
end
|
|
15
14
|
|
|
@@ -77,9 +76,9 @@ module HireFire
|
|
|
77
76
|
# @return [String] in text/html format.
|
|
78
77
|
#
|
|
79
78
|
def build_test_response
|
|
80
|
-
status
|
|
79
|
+
status = 200
|
|
81
80
|
headers = {"Content-Type" => "text/html"}
|
|
82
|
-
body
|
|
81
|
+
body = "HireFire Middleware Found!"
|
|
83
82
|
|
|
84
83
|
[status, headers, [body]]
|
|
85
84
|
end
|
|
@@ -91,14 +90,14 @@ module HireFire
|
|
|
91
90
|
#
|
|
92
91
|
def build_info_response
|
|
93
92
|
entries = HireFire::Resource.dynos.map do |config|
|
|
94
|
-
%({"name":"#{config[:name]}","
|
|
93
|
+
%({"name":"#{config[:name]}","value":#{config[:value].call || "null"}})
|
|
95
94
|
end
|
|
96
95
|
|
|
97
|
-
status
|
|
98
|
-
headers
|
|
99
|
-
headers["Content-Type"]
|
|
96
|
+
status = 200
|
|
97
|
+
headers = {}
|
|
98
|
+
headers["Content-Type"] = "application/json"
|
|
100
99
|
headers["Cache-Control"] = "must-revalidate, private, max-age=0"
|
|
101
|
-
body
|
|
100
|
+
body = "[" + entries.join(",") + "]"
|
|
102
101
|
|
|
103
102
|
[status, headers, [body]]
|
|
104
103
|
end
|
data/lib/hirefire/railtie.rb
CHANGED
data/lib/hirefire/resource.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module HireFire
|
|
4
4
|
module Resource
|
|
@@ -42,10 +42,10 @@ module HireFire
|
|
|
42
42
|
# Will be used through block-style configuration with the `configure` method.
|
|
43
43
|
#
|
|
44
44
|
# @param [Symbol, String] name the name of the dyno as defined in the Procfile.
|
|
45
|
-
# @param [Proc] block an Integer containing the
|
|
45
|
+
# @param [Proc] block an Integer containing the value calculation logic.
|
|
46
46
|
#
|
|
47
47
|
def dyno(name, &block)
|
|
48
|
-
dynos << {
|
|
48
|
+
dynos << {name: name, value: block}
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
end
|
data/lib/hirefire-resource.rb
CHANGED
metadata
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hirefire-resource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.10.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:
|
|
11
|
+
date: 2021-12-14 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
|
|
15
|
-
executables:
|
|
16
|
-
- hirefire
|
|
17
|
-
- hirefireapp
|
|
15
|
+
executables: []
|
|
18
16
|
extensions: []
|
|
19
17
|
extra_rdoc_files: []
|
|
20
18
|
files:
|
|
19
|
+
- ".github/workflows/main.yml"
|
|
21
20
|
- ".gitignore"
|
|
22
21
|
- CHANGELOG.md
|
|
22
|
+
- Gemfile
|
|
23
|
+
- Gemfile.lock
|
|
23
24
|
- LICENSE
|
|
24
25
|
- README.md
|
|
25
26
|
- Rakefile
|
|
26
|
-
- bin/hirefire
|
|
27
|
-
- bin/hirefireapp
|
|
28
27
|
- hirefire-resource.gemspec
|
|
29
28
|
- lib/hirefire-resource.rb
|
|
30
|
-
- lib/hirefire/cli.rb
|
|
31
29
|
- lib/hirefire/macro/bunny.rb
|
|
32
30
|
- lib/hirefire/macro/delayed_job.rb
|
|
33
31
|
- lib/hirefire/macro/good_job.rb
|
|
@@ -62,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
62
60
|
- !ruby/object:Gem::Version
|
|
63
61
|
version: '0'
|
|
64
62
|
requirements: []
|
|
65
|
-
rubygems_version: 3.
|
|
63
|
+
rubygems_version: 3.2.22
|
|
66
64
|
signing_key:
|
|
67
65
|
specification_version: 4
|
|
68
66
|
summary: Autoscaling for your Heroku dynos
|
data/bin/hirefire
DELETED
data/bin/hirefireapp
DELETED
data/lib/hirefire/cli.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require "open-uri"
|
|
4
|
-
require "openssl"
|
|
5
|
-
|
|
6
|
-
OpenSSL::SSL.send(:remove_const, :VERIFY_PEER)
|
|
7
|
-
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
|
8
|
-
|
|
9
|
-
def usage
|
|
10
|
-
puts(<<-EOS)
|
|
11
|
-
|
|
12
|
-
Usage:
|
|
13
|
-
|
|
14
|
-
hirefire http://mydomain.com/
|
|
15
|
-
|
|
16
|
-
Or locally:
|
|
17
|
-
|
|
18
|
-
gem install thin
|
|
19
|
-
[bundle exec] thin start -p 3000
|
|
20
|
-
hirefire http://127.0.0.1:3000/
|
|
21
|
-
|
|
22
|
-
SSL Enabled URLs:
|
|
23
|
-
|
|
24
|
-
hirefire https://mydomain.com/
|
|
25
|
-
|
|
26
|
-
EOS
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
if (url = ARGV[0]).nil?
|
|
30
|
-
usage
|
|
31
|
-
else
|
|
32
|
-
begin
|
|
33
|
-
response = open(File.join(url, "hirefire", "test")).read
|
|
34
|
-
rescue
|
|
35
|
-
puts
|
|
36
|
-
puts "Error: Could not connect to: #{url}"
|
|
37
|
-
usage
|
|
38
|
-
exit 1
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
if response =~ /HireFire/
|
|
42
|
-
puts response
|
|
43
|
-
else
|
|
44
|
-
puts "Error: Could not find HireFire at #{url}."
|
|
45
|
-
exit 1
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|