hirefire-resource 0.9.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff7c7b164fe5e2bb61f464feda1046fff39f0a100825316dc488bf280f73b0b7
4
- data.tar.gz: 840da97d1a8463a1ed71e45bd751c57d90ee2b0e428472871e3142d1c8d03c4e
3
+ metadata.gz: affa2055a22d9ebc019b20ddace8e5fe042bd7c04115735d88fac5710458eb1d
4
+ data.tar.gz: d5b2aa9fade2670ca74f1af8e3ed3ba76cfb0b520d0794077f1e0e0bc5e8459b
5
5
  SHA512:
6
- metadata.gz: 5be7fb8d94c53c24de38fbc2e55dbf4087eac4cfbf6458ca0ec307c502dbdd5b9dec81d932476dac495d9a5ccdb13d9e1a86033f7efc8f32557279a3b94544f0
7
- data.tar.gz: a8c2af9bb6384b663f27ff9267f5b6703425b269c32e302224d43e4defd47d580ded7a3020eec710cdf555dff24f9b241c15e8cbb5a4550296ef927267e99c9a
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,3 +1,8 @@
1
+ ## v0.10.0
2
+
3
+ * Support Latency (Sidekiq)
4
+ * Rename the "quantity" property to "value" in JSON response ("quantity" is still supported)
5
+
1
6
  ## v0.9.1
2
7
 
3
8
  * Support GoodJob > 2.2 where Job class is renamed to Execution
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
8
+
9
+ gem "rake"
10
+ gem "standardrb"
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
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "standard/rake"
@@ -1,21 +1,19 @@
1
- Gem::Specification.new do |gem|
2
- gem.name = "hirefire-resource"
3
- gem.version = "0.9.1"
4
- gem.platform = Gem::Platform::RUBY
5
- gem.authors = "Michael van Rooijen"
6
- gem.email = "michael@hirefire.io"
7
- gem.homepage = "https://www.hirefire.io"
8
- gem.summary = "Autoscaling for your Heroku dynos"
9
- gem.description = "Load- and schedule-based scaling for web- and worker dynos"
10
- gem.licenses = ["Apache License"]
11
- 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 = {
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
- gem.files = %x[git ls-files].split("\n")
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
@@ -27,10 +27,10 @@ module HireFire
27
27
 
28
28
  queues.flatten!
29
29
 
30
- if queues.last.is_a?(Hash)
31
- options = queues.pop
30
+ options = if queues.last.is_a?(Hash)
31
+ queues.pop
32
32
  else
33
- options = {}
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
- return count_messages(channel, queues, options)
46
+ count_messages(channel, queues, options)
47
47
  ensure
48
- if channel
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
- return count_messages(channel, queues, options)
55
+ count_messages(channel, queues, options)
58
56
  ensure
59
- if channel
60
- channel.close
61
- end
62
-
57
+ channel&.close
63
58
  connection.close
64
59
  end
65
60
  else
66
- raise %{Must pass in :connection => rabbitmq_connection or :amqp_url => url\n} +
67
- %{For example: HireFire::Macro::Bunny.queue("queue1", :connection => rabbitmq_connection}
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
- queue = channel.queue(queue_name, :durable => options[:durable],
75
- :arguments => {"x-max-priority" => options[:'x-max-priority']})
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
- queue = channel.queue(queue_name, :durable => options[:durable])
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
- options = queues.pop
38
+ options = if queues.last.is_a?(Hash)
39
+ queues.pop
40
40
  else
41
- options = {}
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(:failed_at => nil)
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(:queue => queues) unless queues.empty?
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(: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)
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(:failed_at => nil)
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 %{Must pass in :mapper => :active_record or :mapper => :mongoid\n} +
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
@@ -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| memo += ::Qu.backend.length(queue); memo }
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
@@ -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 = queues.empty? && base_query || base_query + " AND queue IN (#{names(queues)})"
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
- options = queues.pop
36
+ options = if queues.last.is_a?(Hash)
37
+ queues.pop
28
38
  else
29
- options = {}
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('schedule', '-inf', Time.now.to_f) }
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('retry', '-inf', Time.now.to_f) }
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.select do |key, tid, job|
106
- queues.include?(job['queue']) && job['run_at'] <= now
107
- end.size
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(&:+)
@@ -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 = app
12
- @token = ENV["HIREFIRE_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 = 200
79
+ status = 200
81
80
  headers = {"Content-Type" => "text/html"}
82
- body = "HireFire Middleware Found!"
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]}","quantity":#{config[:quantity].call || "null"}})
93
+ %({"name":"#{config[:name]}","value":#{config[:value].call || "null"}})
95
94
  end
96
95
 
97
- status = 200
98
- headers = Hash.new
99
- headers["Content-Type"] = "application/json"
96
+ status = 200
97
+ headers = {}
98
+ headers["Content-Type"] = "application/json"
100
99
  headers["Cache-Control"] = "must-revalidate, private, max-age=0"
101
- body = "[" + entries.join(",") + "]"
100
+ body = "[" + entries.join(",") + "]"
102
101
 
103
102
  [status, headers, [body]]
104
103
  end
@@ -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 quantity calculation logic.
45
+ # @param [Proc] block an Integer containing the value calculation logic.
46
46
  #
47
47
  def dyno(name, &block)
48
- dynos << { :name => name, :quantity => block }
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.9.1
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-09-17 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require File.expand_path("../../lib/hirefire/cli", __FILE__)
4
-
data/bin/hirefireapp DELETED
@@ -1,5 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- puts "Please use the `hirefire` utility instead of the `hirefireapp` utility."
4
- exit 1
5
-
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