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 +4 -4
- data/CHANGELOG.md +8 -1
- data/Rakefile +2 -0
- data/hirefire-resource.gemspec +1 -3
- data/lib/hirefire-resource.rb +1 -1
- 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 +1 -1
- 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
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f395466dc5805c8bd4d686f22181e515ac14a600e15e062a8e55d582dc6a0e57
|
4
|
+
data.tar.gz: ad6fd4856109de19979e8a975f65c0697672f09ccbbc67ef635c1e83384533d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff67ee5f1bb27f874fbb2f401681ab1fb37c6904f62ac10ab42fb38b256ba1f8638407fc78f914e3aa40c5178c6bffff95a0a40dfab4882aa2726fc815bf8a0
|
7
|
+
data.tar.gz: 52cc6314c95f940140afb1798e2afac18c4cbc7a494f8cc6ea4e3a111aee6fa53876dcb9f85f924a02e843eb560cbc7b755f3ed7e5522d00f1b23f7727e7c70c
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
## v0.
|
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
data/hirefire-resource.gemspec
CHANGED
data/lib/hirefire-resource.rb
CHANGED
data/lib/hirefire/cli.rb
CHANGED
data/lib/hirefire/macro/bunny.rb
CHANGED
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
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.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-
|
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
|