hirefire-resource 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +16 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +49 -0
- data/Rakefile +1 -0
- data/hirefire-resource.gemspec +14 -16
- data/lib/hirefire/macro/bunny.rb +13 -18
- data/lib/hirefire/macro/delayed_job.rb +10 -10
- data/lib/hirefire/macro/qu.rb +4 -1
- data/lib/hirefire/macro/que.rb +1 -1
- data/lib/hirefire/macro/sidekiq.rb +19 -9
- data/lib/hirefire/middleware.rb +9 -10
- data/lib/hirefire/resource.rb +2 -2
- metadata +6 -8
- data/bin/hirefire +0 -4
- data/bin/hirefireapp +0 -5
- data/lib/hirefire/cli.rb +0 -47
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
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/Rakefile
CHANGED
data/hirefire-resource.gemspec
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
-
Gem::Specification.new do |
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 = {
|
12
12
|
"homepage_uri" => "https://www.hirefire.io",
|
13
13
|
"changelog_uri" => "https://github.com/hirefire/hirefire-resource/blob/master/CHANGELOG.md",
|
14
14
|
"source_code_uri" => "https://github.com/hirefire/hirefire-resource/",
|
15
|
-
"bug_tracker_uri" => "https://github.com/hirefire/hirefire-resource/issues"
|
15
|
+
"bug_tracker_uri" => "https://github.com/hirefire/hirefire-resource/issues"
|
16
16
|
}
|
17
|
-
|
18
|
-
|
19
|
-
gem.executables = ["hirefire", "hirefireapp"]
|
20
|
-
gem.require_path = "lib"
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
spec.require_path = "lib"
|
21
19
|
end
|
data/lib/hirefire/macro/bunny.rb
CHANGED
@@ -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
|
@@ -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
|
data/lib/hirefire/macro/qu.rb
CHANGED
@@ -17,7 +17,10 @@ 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
|
data/lib/hirefire/macro/que.rb
CHANGED
@@ -16,7 +16,7 @@ module HireFire
|
|
16
16
|
# @return [Integer] the number of jobs in the queue(s).
|
17
17
|
#
|
18
18
|
def queue(*queues)
|
19
|
-
query
|
19
|
+
query = queues.empty? && base_query || base_query + " AND queue IN (#{names(queues)})"
|
20
20
|
results = ::Que.execute(query).first
|
21
21
|
(results[:total] || results["total"]).to_i
|
22
22
|
end
|
@@ -5,9 +5,19 @@ module HireFire
|
|
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
|
@@ -23,10 +33,10 @@ module HireFire
|
|
23
33
|
|
24
34
|
queues.flatten!
|
25
35
|
|
26
|
-
if queues.last.is_a?(Hash)
|
27
|
-
|
36
|
+
options = if queues.last.is_a?(Hash)
|
37
|
+
queues.pop
|
28
38
|
else
|
29
|
-
|
39
|
+
{}
|
30
40
|
end
|
31
41
|
|
32
42
|
queues.map!(&:to_s)
|
@@ -54,11 +64,11 @@ module HireFire
|
|
54
64
|
in_queues = stats.enqueued
|
55
65
|
|
56
66
|
if !options[:skip_scheduled]
|
57
|
-
in_schedule = ::Sidekiq.redis { |c| c.zcount(
|
67
|
+
in_schedule = ::Sidekiq.redis { |c| c.zcount("schedule", "-inf", Time.now.to_f) }
|
58
68
|
end
|
59
69
|
|
60
70
|
if !options[:skip_retries]
|
61
|
-
in_retry = ::Sidekiq.redis { |c| c.zcount(
|
71
|
+
in_retry = ::Sidekiq.redis { |c| c.zcount("retry", "-inf", Time.now.to_f) }
|
62
72
|
end
|
63
73
|
|
64
74
|
if !options[:skip_working]
|
@@ -102,9 +112,9 @@ module HireFire
|
|
102
112
|
if !options[:skip_working]
|
103
113
|
# Objects yielded to Workers#each:
|
104
114
|
# https://github.com/mperham/sidekiq/blob/305ab8eedc362325da2e218b2a0e20e510668a42/lib/sidekiq/api.rb#L912
|
105
|
-
in_progress = ::Sidekiq::Workers.new.
|
106
|
-
queues.include?(job[
|
107
|
-
end
|
115
|
+
in_progress = ::Sidekiq::Workers.new.count do |key, tid, job|
|
116
|
+
queues.include?(job["queue"]) && job["run_at"] <= now
|
117
|
+
end
|
108
118
|
end
|
109
119
|
|
110
120
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
data/lib/hirefire/middleware.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
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/resource.rb
CHANGED
@@ -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
|
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: 2021-
|
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
|
data/bin/hirefire
DELETED
data/bin/hirefireapp
DELETED
data/lib/hirefire/cli.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
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
|