hirefire-resource 0.8.1 → 0.9.0

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: 78f25c9a7eeb6260b9e218267522c46be2493e9a2a3d9e0fa08b6514a803a62b
4
- data.tar.gz: 52a780c5a441f99a93bce38a496b107b6da34a0a9493c8697b497a5df7912ac3
3
+ metadata.gz: f395466dc5805c8bd4d686f22181e515ac14a600e15e062a8e55d582dc6a0e57
4
+ data.tar.gz: ad6fd4856109de19979e8a975f65c0697672f09ccbbc67ef635c1e83384533d0
5
5
  SHA512:
6
- metadata.gz: 9cdedb2500afde54bc12355bb54c44ac18b572f9c427d3dd2f84a94e4c9fd912bc0fa5400b357511d9ff3329423e6eace83d57fa9ff66ec75600f4ddb2d24856
7
- data.tar.gz: 6da6c56397be5a92a5afb337dfbbc57bea9e775ae62274e92d975d6dd248199557043c9cf115f7a38a5a2aa6838e956868dbe629928c7be70a4a4ca48951fdeb
6
+ metadata.gz: fff67ee5f1bb27f874fbb2f401681ab1fb37c6904f62ac10ab42fb38b256ba1f8638407fc78f914e3aa40c5178c6bffff95a0a40dfab4882aa2726fc815bf8a0
7
+ data.tar.gz: 52cc6314c95f940140afb1798e2afac18c4cbc7a494f8cc6ea4e3a111aee6fa53876dcb9f85f924a02e843eb560cbc7b755f3ed7e5522d00f1b23f7727e7c70c
@@ -1,4 +1,11 @@
1
- ## v0.8.1/Master
1
+ ## v0.9.0/master
2
+
3
+ * Add `skip_working` to Sidekiq macro
4
+ * Use separate queries for Que 0.x and 1.x
5
+ * Remove `# encoding: utf-8` magic comments
6
+ * Add `# frozen_string_literal: true` magic comments
7
+
8
+ ## v0.8.1
2
9
 
3
10
  * Correct GoodJob macro to not count finished jobs.
4
11
 
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.8.1"
3
+ gem.version = "0.9.0"
6
4
  gem.platform = Gem::Platform::RUBY
7
5
  gem.authors = "Michael van Rooijen"
8
6
  gem.email = "michael@hirefire.io"
@@ -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
 
@@ -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
-
@@ -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
@@ -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
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.8.1
4
+ version: 0.9.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: 2020-09-19 00:00:00.000000000 Z
11
+ date: 2020-10-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