hirefire-resource 0.7.5 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/README.md +10 -5
- data/Rakefile +2 -0
- data/hirefire-resource.gemspec +1 -3
- data/lib/hirefire/cli.rb +1 -2
- data/lib/hirefire/macro/bunny.rb +1 -1
- data/lib/hirefire/macro/delayed_job.rb +1 -2
- data/lib/hirefire/macro/good_job.rb +26 -0
- data/lib/hirefire/macro/qc.rb +1 -2
- data/lib/hirefire/macro/qu.rb +1 -2
- data/lib/hirefire/macro/que.rb +32 -13
- data/lib/hirefire/macro/resque.rb +1 -1
- data/lib/hirefire/macro/sidekiq.rb +12 -8
- data/lib/hirefire/middleware.rb +1 -1
- data/lib/hirefire/railtie.rb +1 -1
- data/lib/hirefire/resource.rb +1 -1
- data/lib/hirefire-resource.rb +2 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff7c7b164fe5e2bb61f464feda1046fff39f0a100825316dc488bf280f73b0b7
|
4
|
+
data.tar.gz: 840da97d1a8463a1ed71e45bd751c57d90ee2b0e428472871e3142d1c8d03c4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be7fb8d94c53c24de38fbc2e55dbf4087eac4cfbf6458ca0ec307c502dbdd5b9dec81d932476dac495d9a5ccdb13d9e1a86033f7efc8f32557279a3b94544f0
|
7
|
+
data.tar.gz: a8c2af9bb6384b663f27ff9267f5b6703425b269c32e302224d43e4defd47d580ded7a3020eec710cdf555dff24f9b241c15e8cbb5a4550296ef927267e99c9a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,23 @@
|
|
1
|
-
## v0.
|
1
|
+
## v0.9.1
|
2
|
+
|
3
|
+
* Support GoodJob > 2.2 where Job class is renamed to Execution
|
4
|
+
|
5
|
+
## v0.9.0
|
6
|
+
|
7
|
+
* Add `skip_working` to Sidekiq macro
|
8
|
+
* Use separate queries for Que 0.x and 1.x
|
9
|
+
* Remove `# encoding: utf-8` magic comments
|
10
|
+
* Add `# frozen_string_literal: true` magic comments
|
11
|
+
|
12
|
+
## v0.8.1
|
13
|
+
|
14
|
+
* Correct GoodJob macro to not count finished jobs.
|
15
|
+
|
16
|
+
## v0.8.0
|
17
|
+
|
18
|
+
* Add GoodJob macro for `good_job` adapter. https://github.com/bensheldon/good_job
|
19
|
+
|
20
|
+
## v0.7.5
|
2
21
|
|
3
22
|
* Fix compatibility issue with Que 1.x (backwards-compatible with Que 0.x).
|
4
23
|
|
data/README.md
CHANGED
@@ -1,18 +1,19 @@
|
|
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
|
|
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.*
|
@@ -83,8 +84,12 @@ dj_worker: QUEUES=encode,compress bundle exec rake jobs:work
|
|
83
84
|
|
84
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.
|
85
86
|
|
86
|
-
Visit the [official website]
|
87
|
+
Visit the [official website] for more information!
|
87
88
|
|
88
89
|
### License
|
89
90
|
|
90
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
data/lib/hirefire/cli.rb
CHANGED
data/lib/hirefire/macro/bunny.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
base_class = defined?(::GoodJob::Execution) ? ::GoodJob::Execution : ::GoodJob::Job
|
20
|
+
scope = base_class.only_scheduled.unfinished
|
21
|
+
scope = scope.where(queue_name: queues) if queues.any?
|
22
|
+
scope.count
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/hirefire/macro/qc.rb
CHANGED
data/lib/hirefire/macro/qu.rb
CHANGED
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,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HireFire
|
4
4
|
module Macro
|
@@ -13,6 +13,7 @@ module HireFire
|
|
13
13
|
# HireFire::Macro::Sidekiq.queue("audio", "video") # audio and video queues
|
14
14
|
# HireFire::Macro::Sidekiq.queue("email", skip_scheduled: true) # only email, will not count scheduled queue
|
15
15
|
# HireFire::Macro::Sidekiq.queue("audio", skip_retries: true) # only audio, will not count the retries queue
|
16
|
+
# HireFire::Macro::Sidekiq.queue("audio", skip_working: true) # only audio, will not count already queued
|
16
17
|
#
|
17
18
|
# @param [Array] queues provide one or more queue names, or none for "all".
|
18
19
|
# @return [Integer] the number of jobs in the queue(s).
|
@@ -60,7 +61,9 @@ module HireFire
|
|
60
61
|
in_retry = ::Sidekiq.redis { |c| c.zcount('retry', '-inf', Time.now.to_f) }
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
+
if !options[:skip_working]
|
65
|
+
in_progress = stats.workers_size
|
66
|
+
end
|
64
67
|
|
65
68
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
66
69
|
end
|
@@ -96,15 +99,16 @@ module HireFire
|
|
96
99
|
|
97
100
|
now = Time.now.to_i
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
if !options[:skip_working]
|
103
|
+
# Objects yielded to Workers#each:
|
104
|
+
# https://github.com/mperham/sidekiq/blob/305ab8eedc362325da2e218b2a0e20e510668a42/lib/sidekiq/api.rb#L912
|
105
|
+
in_progress = ::Sidekiq::Workers.new.select do |key, tid, job|
|
106
|
+
queues.include?(job['queue']) && job['run_at'] <= now
|
107
|
+
end.size
|
108
|
+
end
|
104
109
|
|
105
110
|
[in_queues, in_schedule, in_retry, in_progress].compact.inject(&:+)
|
106
111
|
end
|
107
112
|
end
|
108
113
|
end
|
109
114
|
end
|
110
|
-
|
data/lib/hirefire/middleware.rb
CHANGED
data/lib/hirefire/railtie.rb
CHANGED
data/lib/hirefire/resource.rb
CHANGED
data/lib/hirefire-resource.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
HIREFIRE_PATH = File.expand_path("../hirefire", __FILE__)
|
4
4
|
|
@@ -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
|
-
|
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.9.1
|
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-09-17 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
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/hirefire/cli.rb
|
31
31
|
- lib/hirefire/macro/bunny.rb
|
32
32
|
- lib/hirefire/macro/delayed_job.rb
|
33
|
+
- lib/hirefire/macro/good_job.rb
|
33
34
|
- lib/hirefire/macro/qc.rb
|
34
35
|
- lib/hirefire/macro/qu.rb
|
35
36
|
- lib/hirefire/macro/que.rb
|
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
- !ruby/object:Gem::Version
|
62
63
|
version: '0'
|
63
64
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
65
|
+
rubygems_version: 3.2.22
|
65
66
|
signing_key:
|
66
67
|
specification_version: 4
|
67
68
|
summary: Autoscaling for your Heroku dynos
|