hirefire-resource 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/README.md +3 -2
- data/hirefire-resource.gemspec +7 -1
- data/lib/hirefire-resource.rb +1 -2
- data/lib/hirefire/macro/bunny.rb +6 -2
- data/lib/hirefire/macro/good_job.rb +25 -0
- data/lib/hirefire/macro/que.rb +12 -11
- data/lib/hirefire/middleware.rb +5 -9
- data/lib/hirefire/resource.rb +1 -1
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf1b333fe0b454c20c681c25fcc71f0f848f241421ceedde11e30ba5f29a467f
|
4
|
+
data.tar.gz: 76cd10b7c38c130405db1988267cb861c9b0a4ca69a38b8e30404dbc92d576f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab33d00cef820b5f895638e5b905c2ae30fcda10de6d890a168bfa4635643fdb6a2a074ebe1863476d8086c8615974dc0123e0b890e4dd147aea2c135107db7
|
7
|
+
data.tar.gz: df331cea509df6b7c1f58c8d65471479157dd4ce43179d5150b9cfe61144d2d9f1dd7da50cdd455ad28245dafbe748b671a1af72cdccf85846ce304ee25657d7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
## v0.8.0/Master
|
2
|
+
|
3
|
+
* Add GoodJob macro for `good_job` adapter. https://github.com/bensheldon/good_job
|
4
|
+
|
5
|
+
## v0.7.5
|
6
|
+
|
7
|
+
* Fix compatibility issue with Que 1.x (backwards-compatible with Que 0.x).
|
8
|
+
|
9
|
+
## v0.7.4
|
10
|
+
|
11
|
+
* Attempt to fix an issue where the STDOUT IO Stream has been closed for an unknown reason.
|
12
|
+
* This resulted in errors in an application with `log_queue_metrics` enabled after a random period of time.
|
13
|
+
|
14
|
+
## v0.7.3
|
15
|
+
|
16
|
+
* Added priority queue support for bunny message count.
|
17
|
+
* Allows for passing in the `x-max-priority` option when opening up a queue to check the messages remaining.
|
18
|
+
* Usage: `HireFire::Macro::Bunny.queue(queue, amqp_url: url, "x-max-priority": 10 )`
|
19
|
+
|
20
|
+
## v0.7.2
|
21
|
+
|
22
|
+
* Changed Que macro to query take into account scheduled jobs.
|
23
|
+
|
24
|
+
## v0.7.1
|
25
|
+
|
26
|
+
* Made entire library threadsafe.
|
27
|
+
|
28
|
+
## v0.7.0
|
29
|
+
|
30
|
+
* Made `HireFire::Resource.log_queue_metrics` optional. This is now disabled by default.
|
31
|
+
* Enable by setting `log_queue_metrics = true`.
|
32
|
+
* Required when using the `Manager::Web::Logplex::QueueTime` autoscaling strategy.
|
data/README.md
CHANGED
@@ -6,13 +6,14 @@ Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](ht
|
|
6
6
|
|
7
7
|
It supports practically any worker library. We provide out-of-the-box support for:
|
8
8
|
|
9
|
+
* Sidekiq
|
9
10
|
* Delayed Job
|
10
11
|
* Resque
|
12
|
+
* GoodJob
|
11
13
|
* Qu
|
14
|
+
* Que
|
12
15
|
* QueueClassic
|
13
|
-
* Sidekiq
|
14
16
|
* Bunny
|
15
|
-
* Que
|
16
17
|
|
17
18
|
*Note that you can write your own worker queue logic for almost any other worker library as well.
|
18
19
|
HireFire can scale multiple individual worker libraries at the same time, as well as multiple individual queues for any worker library.*
|
data/hirefire-resource.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "hirefire-resource"
|
5
|
-
gem.version = "0.
|
5
|
+
gem.version = "0.8.0"
|
6
6
|
gem.platform = Gem::Platform::RUBY
|
7
7
|
gem.authors = "Michael van Rooijen"
|
8
8
|
gem.email = "michael@hirefire.io"
|
@@ -10,6 +10,12 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.summary = "Autoscaling for your Heroku dynos"
|
11
11
|
gem.description = "Load- and schedule-based scaling for web- and worker dynos"
|
12
12
|
gem.licenses = ["Apache License"]
|
13
|
+
gem.metadata = {
|
14
|
+
"homepage_uri" => "https://www.hirefire.io",
|
15
|
+
"changelog_uri" => "https://github.com/hirefire/hirefire-resource/blob/master/CHANGELOG.md",
|
16
|
+
"source_code_uri" => "https://github.com/hirefire/hirefire-resource/",
|
17
|
+
"bug_tracker_uri" => "https://github.com/hirefire/hirefire-resource/issues",
|
18
|
+
}
|
13
19
|
|
14
20
|
gem.files = %x[git ls-files].split("\n")
|
15
21
|
gem.executables = ["hirefire", "hirefireapp"]
|
data/lib/hirefire-resource.rb
CHANGED
@@ -6,9 +6,8 @@ HIREFIRE_PATH = File.expand_path("../hirefire", __FILE__)
|
|
6
6
|
require "#{HIREFIRE_PATH}/#{file}"
|
7
7
|
end
|
8
8
|
|
9
|
-
%w[delayed_job resque sidekiq qu qc bunny que].each do |file|
|
9
|
+
%w[delayed_job resque sidekiq qu qc bunny que good_job].each do |file|
|
10
10
|
require "#{HIREFIRE_PATH}/macro/#{file}"
|
11
11
|
end
|
12
12
|
|
13
13
|
require "#{HIREFIRE_PATH}/railtie" if defined?(Rails::Railtie)
|
14
|
-
|
data/lib/hirefire/macro/bunny.rb
CHANGED
@@ -70,11 +70,15 @@ module HireFire
|
|
70
70
|
|
71
71
|
def count_messages(channel, queue_names, options)
|
72
72
|
queue_names.inject(0) do |sum, queue_name|
|
73
|
-
|
73
|
+
if options.key?(:'x-max-priority')
|
74
|
+
queue = channel.queue(queue_name, :durable => options[:durable],
|
75
|
+
:arguments => {"x-max-priority" => options[:'x-max-priority']})
|
76
|
+
else
|
77
|
+
queue = channel.queue(queue_name, :durable => options[:durable])
|
78
|
+
end
|
74
79
|
sum + queue.message_count
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
|
-
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module HireFire
|
4
|
+
module Macro
|
5
|
+
module GoodJob
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Queries the PostgreSQL database through GoodJob in order to
|
9
|
+
# count the amount of jobs in the specified queue.
|
10
|
+
#
|
11
|
+
# @example Queue Macro Usage
|
12
|
+
# HireFire::Macro::GoodJob.queue # counts all queues.
|
13
|
+
# HireFire::Macro::GoodJob.queue("email") # counts the `email` queue.
|
14
|
+
#
|
15
|
+
# @param [String] queue the queue name to count. (default: nil # gets all queues)
|
16
|
+
# @return [Integer] the number of jobs in the queue(s).
|
17
|
+
#
|
18
|
+
def queue(*queues)
|
19
|
+
scope = ::GoodJob::Job.only_scheduled
|
20
|
+
scope = scope.where(queue_name: queues) if queues.any?
|
21
|
+
scope.count
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/hirefire/macro/que.rb
CHANGED
@@ -4,14 +4,8 @@ module HireFire
|
|
4
4
|
module Macro
|
5
5
|
module Que
|
6
6
|
QUERY = %{
|
7
|
-
SELECT count(*)
|
8
|
-
|
9
|
-
coalesce(sum((error_count > 0 AND locks.job_id IS NULL)::int), 0) AS failing,
|
10
|
-
coalesce(sum((error_count = 0 AND locks.job_id IS NULL)::int), 0) AS scheduled
|
11
|
-
FROM que_jobs LEFT JOIN (
|
12
|
-
SELECT (classid::bigint << 32) + objid::bigint AS job_id
|
13
|
-
FROM pg_locks WHERE locktype = 'advisory'
|
14
|
-
) locks USING (job_id) }.freeze
|
7
|
+
SELECT count(*) AS total
|
8
|
+
FROM que_jobs WHERE run_at < now() }.freeze
|
15
9
|
|
16
10
|
extend self
|
17
11
|
|
@@ -25,10 +19,17 @@ FROM que_jobs LEFT JOIN (
|
|
25
19
|
# @param [String] queue the queue name to count. (default: nil # gets all queues)
|
26
20
|
# @return [Integer] the number of jobs in the queue(s).
|
27
21
|
#
|
28
|
-
def queue(
|
29
|
-
query =
|
22
|
+
def queue(*queues)
|
23
|
+
query = case
|
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
|
+
|
30
31
|
results = ::Que.execute(query).first
|
31
|
-
results[
|
32
|
+
(results[:total] || results["total"]).to_i
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
data/lib/hirefire/middleware.rb
CHANGED
@@ -19,7 +19,7 @@ module HireFire
|
|
19
19
|
#
|
20
20
|
# When HireFire::Resource.log_queue_metrics is enabled, and the HTTP_X_REQUEST_START
|
21
21
|
# header has been injected at the Heroku Router layer, queue time information will be
|
22
|
-
# logged to
|
22
|
+
# logged to $stdout. This data can be used by the HireFire Logdrain with the
|
23
23
|
# Web.Logplex.QueueTime autoscaling strategy.
|
24
24
|
#
|
25
25
|
# Important: Don't set/update instance variables within this- or any underlying methods.
|
@@ -90,14 +90,10 @@ module HireFire
|
|
90
90
|
# @return [String] in application/json format.
|
91
91
|
#
|
92
92
|
def build_info_response
|
93
|
-
|
93
|
+
entries = HireFire::Resource.dynos.map do |config|
|
94
94
|
%({"name":"#{config[:name]}","quantity":#{config[:quantity].call || "null"}})
|
95
95
|
end
|
96
96
|
|
97
|
-
entries = HireFire::Resource.dynos.inject([]) do |buffer, config|
|
98
|
-
buffer << entry_builder.call(config)
|
99
|
-
end
|
100
|
-
|
101
97
|
status = 200
|
102
98
|
headers = Hash.new
|
103
99
|
headers["Content-Type"] = "application/json"
|
@@ -107,7 +103,7 @@ module HireFire
|
|
107
103
|
[status, headers, [body]]
|
108
104
|
end
|
109
105
|
|
110
|
-
# Writes the Heroku Router queue time to
|
106
|
+
# Writes the Heroku Router queue time to $stdout if a String was provided.
|
111
107
|
#
|
112
108
|
# @param [String] the timestamp from HTTP_X_REQUEST_START.
|
113
109
|
#
|
@@ -115,12 +111,12 @@ module HireFire
|
|
115
111
|
HireFire::Resource.log_queue_metrics && value && log_queue(value)
|
116
112
|
end
|
117
113
|
|
118
|
-
# Writes the Heroku Router queue time to
|
114
|
+
# Writes the Heroku Router queue time to $stdout.
|
119
115
|
#
|
120
116
|
# @param [String] the timestamp from HTTP_X_REQUEST_START.
|
121
117
|
#
|
122
118
|
def log_queue(value)
|
123
|
-
|
119
|
+
puts("[hirefire:router] queue=#{get_queue(value)}ms")
|
124
120
|
end
|
125
121
|
|
126
122
|
# Calculates the difference, in milliseconds, between the
|
data/lib/hirefire/resource.rb
CHANGED
@@ -4,7 +4,7 @@ module HireFire
|
|
4
4
|
module Resource
|
5
5
|
extend self
|
6
6
|
|
7
|
-
# This option, when enabled, will write queue metrics to
|
7
|
+
# This option, when enabled, will write queue metrics to $stdout,
|
8
8
|
# and is only required when using the Web.Logplex.QueueTime strategy.
|
9
9
|
#
|
10
10
|
# @param [Boolean] Whether or not the queue metrics should be logged.
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-10 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
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- ".gitignore"
|
22
|
+
- CHANGELOG.md
|
22
23
|
- LICENSE
|
23
24
|
- README.md
|
24
25
|
- Rakefile
|
@@ -29,6 +30,7 @@ files:
|
|
29
30
|
- lib/hirefire/cli.rb
|
30
31
|
- lib/hirefire/macro/bunny.rb
|
31
32
|
- lib/hirefire/macro/delayed_job.rb
|
33
|
+
- lib/hirefire/macro/good_job.rb
|
32
34
|
- lib/hirefire/macro/qc.rb
|
33
35
|
- lib/hirefire/macro/qu.rb
|
34
36
|
- lib/hirefire/macro/que.rb
|
@@ -40,8 +42,12 @@ files:
|
|
40
42
|
homepage: https://www.hirefire.io
|
41
43
|
licenses:
|
42
44
|
- Apache License
|
43
|
-
metadata:
|
44
|
-
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://www.hirefire.io
|
47
|
+
changelog_uri: https://github.com/hirefire/hirefire-resource/blob/master/CHANGELOG.md
|
48
|
+
source_code_uri: https://github.com/hirefire/hirefire-resource/
|
49
|
+
bug_tracker_uri: https://github.com/hirefire/hirefire-resource/issues
|
50
|
+
post_install_message:
|
45
51
|
rdoc_options: []
|
46
52
|
require_paths:
|
47
53
|
- lib
|
@@ -56,9 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
62
|
- !ruby/object:Gem::Version
|
57
63
|
version: '0'
|
58
64
|
requirements: []
|
59
|
-
|
60
|
-
|
61
|
-
signing_key:
|
65
|
+
rubygems_version: 3.1.2
|
66
|
+
signing_key:
|
62
67
|
specification_version: 4
|
63
68
|
summary: Autoscaling for your Heroku dynos
|
64
69
|
test_files: []
|