hirefire-resource 0.9.1 → 0.10.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: ff7c7b164fe5e2bb61f464feda1046fff39f0a100825316dc488bf280f73b0b7
4
- data.tar.gz: 840da97d1a8463a1ed71e45bd751c57d90ee2b0e428472871e3142d1c8d03c4e
3
+ metadata.gz: a071158b508eb303b36e2e62e11ef4acfd104b4d3c2fb1431ce042587ce1c6e4
4
+ data.tar.gz: 8393b0eaf605fd706980506413d0424b5cf003d337e4930f8280cbf386602c22
5
5
  SHA512:
6
- metadata.gz: 5be7fb8d94c53c24de38fbc2e55dbf4087eac4cfbf6458ca0ec307c502dbdd5b9dec81d932476dac495d9a5ccdb13d9e1a86033f7efc8f32557279a3b94544f0
7
- data.tar.gz: a8c2af9bb6384b663f27ff9267f5b6703425b269c32e302224d43e4defd47d580ded7a3020eec710cdf555dff24f9b241c15e8cbb5a4550296ef927267e99c9a
6
+ metadata.gz: e24741c9418227b9264499f9216af379f01f6036a8926ad0093f2412b09c83bafa0b276929d9388c9c05f08584c67714d39676b6675e4ae65b0b251f353884c5
7
+ data.tar.gz: 0fa7878f1f5c005928dbb26def63f11f0ad18b9bb425512eb6d37a922c407b05b5d81cfe651428c59be040c3f11b4c4b3f5df6057c4b1372b829f102a068114e
@@ -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.1
14
+ bundler-cache: true
15
+ - name: Run standardrb
16
+ run: bin/rake standard
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## v0.10.1
2
+
3
+ * Add redis 5 (gem) support to HireFire::Macro::Resque
4
+
5
+ ## v0.10.0
6
+
7
+ * Support Latency (Sidekiq)
8
+ * Rename the "quantity" property to "value" in JSON response ("quantity" is still supported)
9
+
1
10
  ## v0.9.1
2
11
 
3
12
  * 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,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hirefire-resource (0.10.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ json (2.6.2)
11
+ parallel (1.22.1)
12
+ parser (3.1.2.1)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.1.1)
15
+ rake (13.0.6)
16
+ regexp_parser (2.6.0)
17
+ rexml (3.2.5)
18
+ rubocop (1.35.1)
19
+ json (~> 2.3)
20
+ parallel (~> 1.10)
21
+ parser (>= 3.1.2.1)
22
+ rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
+ rexml (>= 3.2.5, < 4.0)
25
+ rubocop-ast (>= 1.20.1, < 2.0)
26
+ ruby-progressbar (~> 1.7)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.22.0)
29
+ parser (>= 3.1.1.0)
30
+ rubocop-performance (1.14.3)
31
+ rubocop (>= 1.7.0, < 2.0)
32
+ rubocop-ast (>= 0.4.0)
33
+ ruby-progressbar (1.11.0)
34
+ standard (1.16.1)
35
+ rubocop (= 1.35.1)
36
+ rubocop-performance (= 1.14.3)
37
+ standardrb (1.0.1)
38
+ standard
39
+ unicode-display_width (2.3.0)
40
+
41
+ PLATFORMS
42
+ arm64-darwin-21
43
+ x86_64-darwin-20
44
+ x86_64-linux
45
+
46
+ DEPENDENCIES
47
+ hirefire-resource!
48
+ rake
49
+ standardrb
50
+
51
+ BUNDLED WITH
52
+ 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"
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "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.1"
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
@@ -23,10 +23,12 @@ module HireFire
23
23
 
24
24
  redis = ::Resque.redis
25
25
  ids = Array(redis.smembers(:workers)).compact
26
- raw_jobs = redis.pipelined { ids.map { |id| redis.get("worker:#{id}") } }
26
+ raw_jobs = redis.pipelined do |redis|
27
+ ids.map { |id| redis.get("worker:#{id}") }
28
+ end
27
29
  jobs = raw_jobs.map { |raw_job| ::Resque.decode(raw_job) || {} }
28
30
 
29
- in_queues = redis.pipelined do
31
+ in_queues = redis.pipelined do |redis|
30
32
  queues.map { |queue| redis.llen("queue:#{queue}") }
31
33
  end.map(&:to_i).inject(&:+)
32
34
 
@@ -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,32 @@
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.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: 2021-09-17 00:00:00.000000000 Z
11
+ date: 2022-10-20 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
27
+ - bin/rake
28
28
  - hirefire-resource.gemspec
29
29
  - lib/hirefire-resource.rb
30
- - lib/hirefire/cli.rb
31
30
  - lib/hirefire/macro/bunny.rb
32
31
  - lib/hirefire/macro/delayed_job.rb
33
32
  - lib/hirefire/macro/good_job.rb
@@ -62,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  requirements: []
65
- rubygems_version: 3.2.22
64
+ rubygems_version: 3.3.11
66
65
  signing_key:
67
66
  specification_version: 4
68
67
  summary: Autoscaling for your Heroku dynos
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