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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c7c314af60ca51b3e19880d4f676a5e07ecb5625d8078b7200827a9b2c9338b
4
- data.tar.gz: 486392f48c5986bdf100c03a2047496a840c788ffc2af2e27712d41ce6c6cc0b
3
+ metadata.gz: ff7c7b164fe5e2bb61f464feda1046fff39f0a100825316dc488bf280f73b0b7
4
+ data.tar.gz: 840da97d1a8463a1ed71e45bd751c57d90ee2b0e428472871e3142d1c8d03c4e
5
5
  SHA512:
6
- metadata.gz: c10d31c05160fcd258c804e9e7e1ca9d4e608d71ef0a579255f03cac37c2f50b5a81e4c8ea9c24abf57179c3e0e86c5616a0855cee52561eb793d2957608edd2
7
- data.tar.gz: b44fd34a1ec5395d2734745e1f72b6a189f37aa285d67177e19764619de1c4770d6a6f40d133cc02e6e3285cc781761df03b9cfb63916974731d2de02325d023
6
+ metadata.gz: 5be7fb8d94c53c24de38fbc2e55dbf4087eac4cfbf6458ca0ec307c502dbdd5b9dec81d932476dac495d9a5ccdb13d9e1a86033f7efc8f32557279a3b94544f0
7
+ data.tar.gz: a8c2af9bb6384b663f27ff9267f5b6703425b269c32e302224d43e4defd47d580ded7a3020eec710cdf555dff24f9b241c15e8cbb5a4550296ef927267e99c9a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,23 @@
1
- ## v0.7.5/Master
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](https://www.hirefire.io/) - Autoscaling for your Heroku dynos
1
+ ## [HireFire] - Autoscaling for [Heroku]
2
2
 
3
- Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](https://www.heroku.com/) web- and worker dynos.
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](https://www.hirefire.io/) for more information!
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
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
2
-
3
1
  Gem::Specification.new do |gem|
4
2
  gem.name = "hirefire-resource"
5
- gem.version = "0.7.5"
3
+ gem.version = "0.9.1"
6
4
  gem.platform = Gem::Platform::RUBY
7
5
  gem.authors = "Michael van Rooijen"
8
6
  gem.email = "michael@hirefire.io"
data/lib/hirefire/cli.rb CHANGED
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require "open-uri"
4
4
  require "openssl"
@@ -45,4 +45,3 @@ else
45
45
  exit 1
46
46
  end
47
47
  end
48
-
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Macro
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Macro
@@ -78,4 +78,3 @@ module HireFire
78
78
  end
79
79
  end
80
80
  end
81
-
@@ -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
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Macro
@@ -21,4 +21,3 @@ module HireFire
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Macro
@@ -22,4 +22,3 @@ module HireFire
22
22
  end
23
23
  end
24
24
  end
25
-
@@ -1,12 +1,8 @@
1
- # encoding: utf-8
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 = 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
-
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
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Macro
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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
- in_progress = stats.workers_size
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
- # 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
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
-
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  class Middleware
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  class Railtie < ::Rails::Railtie
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
4
  module Resource
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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.7.5
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: 2020-08-30 00:00:00.000000000 Z
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.1.2
65
+ rubygems_version: 3.2.22
65
66
  signing_key:
66
67
  specification_version: 4
67
68
  summary: Autoscaling for your Heroku dynos