hirefire-resource 1.0.2 → 1.0.4

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: a7b610268d577eb8e6f9a45e515e01484f15a6d8ad57c82073dac2ccd89ae84f
4
- data.tar.gz: 2bf77a2f62178e7f77b956d81344005aff9b247b09252e577f669a685c599417
3
+ metadata.gz: 1d0159499127d61d2281f345a3c4b50cb1a975012aed540d34a6463b53d5cc77
4
+ data.tar.gz: 6424c3fd3462880b0e2a635ddde4fefdce30740b4eee3edaabf7ff9d29a0a895
5
5
  SHA512:
6
- metadata.gz: 42acb0f1d897f2ad80305d4618943d55e1b8a47bd7caad542ed799e52862572f6e97c247440955b6b80ddd4062df64e35635754bf3e053df63910820f88599fd
7
- data.tar.gz: 99706744f9945b01b8498fb19408785df2351367e8358f505e153462f582ef32f413855e75b99e428cf9fd1fa692cf8e00ef9c0850e4745aa4ea3fdf6320edf2
6
+ metadata.gz: 60f7e44322babde5329e98b57c0698cd0ac9824f98cb4d83de30cd9dc750fdfb8845ddd8916a754d62011f397a2565afe437dd71b1d8f36ab4d8fa6f634cde96
7
+ data.tar.gz: f40b10e7e7d7a24824970f19a235619feec0171c374ca5a16ff5263c3a36996a44ad3088ab6aacee7cf8bf9abdf6175d8faa43cb5fc7bc2f4d255ce3ace0dd08
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v1.0.4
2
+
3
+ * Add support for `good_job ~> 4`, for the `job_queue_size`, `job_queue_latency` and `queue` (deprecated) macros.
4
+
5
+ ## v1.0.3
6
+
7
+ * Add support for `que ~> 0` and `que ~> 1`, in addition to `que ~> 2`, for both the `job_queue_size` and `job_queue_latency` macros.
8
+
1
9
  ## v1.0.2
2
10
 
3
11
  * Add support for dashes in `HireFire::Worker` names to match the Procfile process naming format. `HireFire::Worker` is implicitly used when configuring HireFire using the `HireFire::Configuration#dyno` method.
data/README.md CHANGED
@@ -38,10 +38,11 @@ For more information, visit our [home page][HireFire].
38
38
  ## Release
39
39
 
40
40
  1. Update the `HireFire::VERSION` constant.
41
- 2. Ensure that `CHANGELOG.md` is up-to-date.
42
- 3. Commit changes with `git commit`.
43
- 4. Create a `git tag` matching the new version (e.g., `v1.0.0`).
44
- 5. Push the new git tag. Continuous Integration will handle the distribution process.
41
+ 2. Update Gemfile locks with `bundle` and `bundle exec appraisal`.
42
+ 3. Ensure that `CHANGELOG.md` is up-to-date.
43
+ 4. Commit changes with `git commit`.
44
+ 5. Create a `git tag` matching the new version (e.g., `v1.0.0`).
45
+ 6. Push the new git tag. Continuous Integration will handle the distribution process.
45
46
 
46
47
  ## License
47
48
 
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "hirefire/macro/helpers/good_job"
4
+
3
5
  module HireFire
4
6
  module Macro
5
7
  module Deprecated
6
8
  # Provides backward compatibility with the deprecated GoodJob macro.
7
9
  # For new implementations, refer to {HireFire::Macro::GoodJob}.
8
10
  module GoodJob
11
+ include HireFire::Macro::Helpers::GoodJob
12
+
9
13
  # Retrieves the total number of jobs in the specified queue(s) using GoodJob.
10
14
  #
11
15
  # This method queries the PostgreSQL database through GoodJob. It's capable
@@ -21,8 +25,7 @@ module HireFire
21
25
  # @example Counting jobs in the "default" queue
22
26
  # HireFire::Macro::GoodJob.queue("default")
23
27
  def queue(*queues)
24
- base_class = defined?(::GoodJob::Execution) ? ::GoodJob::Execution : ::GoodJob::Job
25
- scope = base_class.only_scheduled.unfinished
28
+ scope = good_job_class.only_scheduled.unfinished
26
29
  scope = scope.where(queue_name: queues) if queues.any?
27
30
  scope.count
28
31
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "helpers/good_job"
3
4
  require_relative "deprecated/good_job"
4
5
 
5
6
  module HireFire
6
7
  module Macro
7
8
  module GoodJob
8
- extend HireFire::Macro::Deprecated::GoodJob
9
9
  extend HireFire::Utility
10
+ extend HireFire::Macro::Helpers::GoodJob
11
+ extend HireFire::Macro::Deprecated::GoodJob
10
12
  extend self
11
13
 
12
14
  # Calculates the maximum job queue latency using GoodJob. If no queues are specified, it
@@ -23,9 +25,9 @@ module HireFire
23
25
  # HireFire::Macro::GoodJob.job_queue_latency(:default, :mailer)
24
26
  def job_queue_latency(*queues)
25
27
  queues = normalize_queues(queues, allow_empty: true)
26
- query = ::GoodJob::Execution
28
+ query = good_job_class
27
29
  query = query.where(queue_name: queues) if queues.any?
28
- query = query.where(finished_at: nil)
30
+ query = query.where(performed_at: nil)
29
31
  query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil))
30
32
  query = query.order(scheduled_at: :asc, created_at: :asc)
31
33
 
@@ -50,9 +52,9 @@ module HireFire
50
52
  # HireFire::Macro::GoodJob.job_queue_size(:default, :mailer)
51
53
  def job_queue_size(*queues)
52
54
  queues = normalize_queues(queues, allow_empty: true)
53
- query = ::GoodJob::Execution
55
+ query = good_job_class
54
56
  query = query.where(queue_name: queues) if queues.any?
55
- query = query.where(finished_at: nil)
57
+ query = query.where(performed_at: nil)
56
58
  query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil))
57
59
  query.count
58
60
  end
@@ -0,0 +1,19 @@
1
+ module HireFire
2
+ module Macro
3
+ module Helpers
4
+ module GoodJob
5
+ def self.included(base)
6
+ base.send(:private, :good_job_class)
7
+ end
8
+
9
+ def good_job_class
10
+ if Gem::Version.new(::GoodJob::VERSION) >= Gem::Version.new("4.0.0")
11
+ ::GoodJob::Job
12
+ else
13
+ ::GoodJob::Execution
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -9,6 +9,8 @@ module HireFire
9
9
  extend HireFire::Utility
10
10
  extend self
11
11
 
12
+ VERSION_1_0_0 = Gem::Version.new("1.0.0")
13
+
12
14
  # Calculates the maximum job queue latency using Que. If no queues are specified, it
13
15
  # measures latency across all available queues.
14
16
  #
@@ -22,17 +24,11 @@ module HireFire
22
24
  # @example Calculate latency across "default" and "mailer" queues
23
25
  # HireFire::Macro::Que.job_queue_latency(:default, :mailer)
24
26
  def job_queue_latency(*queues)
25
- query = <<~SQL
26
- SELECT run_at FROM que_jobs
27
- WHERE run_at <= NOW()
28
- AND finished_at IS NULL
29
- AND expired_at IS NULL
30
- #{filter_by_queues_if_any(queues)}
31
- ORDER BY run_at ASC LIMIT 1
32
- SQL
33
-
34
- result = ::Que.execute(query).first
35
- result ? (Time.now - result[:run_at].to_time) : 0.0
27
+ if version < VERSION_1_0_0
28
+ job_queue_latency_v0(*queues)
29
+ else
30
+ job_queue_latency_v1_v2(*queues)
31
+ end
36
32
  end
37
33
 
38
34
  # Calculates the total job queue size using Que. If no queues are specified, it
@@ -48,18 +44,75 @@ module HireFire
48
44
  # @example Calculate size across "default" and "mailer" queues
49
45
  # HireFire::Macro::Que.job_queue_size(:default, :mailer)
50
46
  def job_queue_size(*queues)
47
+ if version < VERSION_1_0_0
48
+ job_queue_size_v0(*queues)
49
+ else
50
+ job_queue_size_v1_v2(*queues)
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def job_queue_latency_v0(*queues)
51
57
  query = <<~SQL
52
- SELECT COUNT(*) AS total FROM que_jobs
58
+ SELECT run_at
59
+ FROM que_jobs
60
+ WHERE run_at <= NOW()
61
+ #{filter_by_queues_if_any(queues)}
62
+ ORDER BY run_at ASC
63
+ LIMIT 1
64
+ SQL
65
+
66
+ query_job_queue_latency(query)
67
+ end
68
+
69
+ def job_queue_latency_v1_v2(*queues)
70
+ query = <<~SQL
71
+ SELECT run_at
72
+ FROM que_jobs
53
73
  WHERE run_at <= NOW()
54
74
  AND finished_at IS NULL
55
75
  AND expired_at IS NULL
56
76
  #{filter_by_queues_if_any(queues)}
77
+ ORDER BY run_at ASC
78
+ LIMIT 1
57
79
  SQL
58
80
 
59
- ::Que.execute(query).first.fetch(:total).to_i
81
+ query_job_queue_latency(query)
60
82
  end
61
83
 
62
- private
84
+ def job_queue_size_v0(*queues)
85
+ query = <<~SQL
86
+ SELECT COUNT(*) AS job_queue_size
87
+ FROM que_jobs
88
+ WHERE run_at <= NOW()
89
+ #{filter_by_queues_if_any(queues)}
90
+ SQL
91
+
92
+ query_job_queue_size(query)
93
+ end
94
+
95
+ def job_queue_size_v1_v2(*queues)
96
+ query = <<~SQL
97
+ SELECT COUNT(*) AS job_queue_size
98
+ FROM que_jobs
99
+ WHERE run_at <= NOW()
100
+ AND finished_at IS NULL
101
+ AND expired_at IS NULL
102
+ #{filter_by_queues_if_any(queues)}
103
+ SQL
104
+
105
+ query_job_queue_size(query)
106
+ end
107
+
108
+ def query_job_queue_latency(query)
109
+ result = ::Que.execute(query).first
110
+ result ? (Time.now - result[:run_at].to_time) : 0.0
111
+ end
112
+
113
+ def query_job_queue_size(query)
114
+ ::Que.execute(query).first.fetch(:job_queue_size).to_i
115
+ end
63
116
 
64
117
  def filter_by_queues_if_any(queues)
65
118
  queues = normalize_queues(queues, allow_empty: true)
@@ -70,6 +123,10 @@ module HireFire
70
123
  def sanitize_sql(value)
71
124
  "'" + value.to_s.gsub(/['"\\]/, '\\\\\\&') + "'"
72
125
  end
126
+
127
+ def version
128
+ Gem::Version.new(defined?(::Que::Version) ? ::Que::Version : ::Que::VERSION)
129
+ end
73
130
  end
74
131
  end
75
132
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HireFire
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
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: 1.0.2
4
+ version: 1.0.4
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: 2024-03-13 00:00:00.000000000 Z
11
+ date: 2024-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -50,6 +50,7 @@ files:
50
50
  - lib/hirefire/macro/deprecated/resque.rb
51
51
  - lib/hirefire/macro/deprecated/sidekiq.rb
52
52
  - lib/hirefire/macro/good_job.rb
53
+ - lib/hirefire/macro/helpers/good_job.rb
53
54
  - lib/hirefire/macro/que.rb
54
55
  - lib/hirefire/macro/queue_classic.rb
55
56
  - lib/hirefire/macro/resque.rb
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  - !ruby/object:Gem::Version
87
88
  version: '0'
88
89
  requirements: []
89
- rubygems_version: 3.5.3
90
+ rubygems_version: 3.5.11
90
91
  signing_key:
91
92
  specification_version: 4
92
93
  summary: HireFire integration library for Ruby applications