yabeda-resque 1.1.0 → 1.3.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: fc64c43baf725df7a5f4691a877bf32907d1b2416bdd6835dbe1c43f002d7a01
4
- data.tar.gz: e72afe1ba6efb66cca854f9f093a230e434450afcfa87c230eeee9aba29a046f
3
+ metadata.gz: f8679f70e3f362a27c2e217852e5e2ca48718ba66cf4bdf929d57252dfb56726
4
+ data.tar.gz: ce6340bbc3f60d3c20bd6dc23fe09ff43efe44bf71bede21112d6a41905f45d3
5
5
  SHA512:
6
- metadata.gz: 3acc9b46978e547bf10fbee16bdc0cd5053d9d8bbe710e0c7353ab79a0cfd577eed7547e0e05a6aee9e78040ac85c46fed4fbb4cfca8160e490de1c1d4fece9f
7
- data.tar.gz: 85e7422c3cd1ecc4835de4ae1c5ff3438fac117ab22ad873242ee962e8ff42296aacf41ee186c4344e549c1842c4741f15c7e20b1ccb6197f66e261ca0da4423
6
+ metadata.gz: a38fd70482feffcab13f959625a426424f8b79e45cbdd7ceb2bf78b4d3df567f7ea31dd5c6b9339051cea10b0c53f9f9eaf2ca96f2457feee51a359ef8c63a65
7
+ data.tar.gz: 70629efcd1073097faee26feb96eb486a6baed2ebae5e41ac3716d2d67ea750abff78632e7f3c1f28f6d8b65d9e401f0dd25522095ea8259ce232c2c011aa32d
data/CHANGELOG.md CHANGED
@@ -1,14 +1,19 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.1.0] - 2025-02-4
3
+ ## [1.3.0] - 2026-05-11
4
+ - Improve Performance of delayed job counting (#1, by @top-sigrid)
5
+
6
+ ## [1.2.0] - 2025-05-16
7
+ - Add jobs_processing_oldest_age metric with unit as config option
8
+
9
+ ## [1.1.0] - 2025-02-14
4
10
  - Fix: queue_sizes metric not being exported
5
11
 
6
- ## [1.0.0] - 2025-02-4
12
+ ## [1.0.0] - 2025-02-14
7
13
  - Add queue_size metric
8
14
  - Add jobs_delayed metric for resque-scheduler
9
15
 
10
16
  ## [0.1.0] - 2025-02-13
11
-
12
17
  - Add jobs_pending metric
13
18
  - Add jobs_processed metric
14
19
  - Add jobs_failed metric
data/README.md CHANGED
@@ -22,16 +22,24 @@ Add the following code to your existing Yabeda setup:
22
22
  Yabeda::Resque.install!
23
23
  ```
24
24
 
25
+ ## Configuration
26
+
27
+ Configuration can be passed to the `Yabeda::Resque.install!` method, e.g.: `Yabeda::Resque.install!(option_name: :value)` The following options are available:
28
+
29
+ * `jobs_processing_oldest_age_unit`:
30
+ The unit of the `jobs_processing_oldest_age` metric. This can be set to `:seconds`, `:minutes`, `:hours` or `:days`. The default value is nil, which means the metric is turned off and will not collected.
31
+
25
32
  ## Provided metrics
26
33
 
27
- | Metric name | Type | Tags | Description |
28
- |-------------------|-------|--------------|-------------------------------------|
29
- | `jobs_pending` | gauge | none | Number of jobs in all queues |
30
- | `jobs_processed` | gauge | none | Number of jobs processed |
31
- | `jobs_failed` | gauge | none | Number of jobs currently failed |
32
- | `workers_total` | gauge | none | Number of workers |
33
- | `workers_working` | gauge | none | Number of workers currently working |
34
- | `queue_sizes` | gauge | queue (name) | Number of jobs in a specific queue |
34
+ | Metric name | Type | Tags | Description |
35
+ |-------------------|-------|----------|------------------------------------------------------|
36
+ | `jobs_pending` | gauge | none | Number of jobs in all queues |
37
+ | `jobs_processed` | gauge | none | Number of jobs processed |
38
+ | `jobs_failed` | gauge | none | Number of jobs currently failed |
39
+ | `workers_total` | gauge | none | Number of workers |
40
+ | `workers_working` | gauge | none | Number of workers currently working |
41
+ | `queue_sizes` | gauge | queue (name) | Number of jobs in a specific queue |
42
+ | `jobs_processing_oldest_age` | gauge | none | Age of the oldest processing job (unit configurable) |
35
43
 
36
44
  Yabeda::Resque detects if [resque-scheduler](https://github.com/resque/resque-scheduler) is being used and adds the following metrics:
37
45
 
@@ -46,7 +54,7 @@ included in the `queue_sizes` metric. Gathering this information can be quite ex
46
54
 
47
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
56
 
49
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, commit it, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
58
 
51
59
  ## Contributing
52
60
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Resque
5
- VERSION = "1.1.0"
5
+ VERSION = "1.3.0"
6
6
  end
7
7
  end
data/lib/yabeda/resque.rb CHANGED
@@ -8,11 +8,52 @@ require "resque"
8
8
  module Yabeda
9
9
  module Resque
10
10
  class << self
11
+ DEFAULT_CONFIG = {
12
+ jobs_processing_oldest_age_unit: nil
13
+ }.freeze
14
+
11
15
  def monitor_delayed?
12
16
  defined?(::Resque::Scheduler)
13
17
  end
14
18
 
15
- def install!
19
+ # Pipelined alternative to Resque.count_all_scheduled_jobs from resque-scheduler.
20
+ # The original implementation issues a sequential LLEN call per timestamp, resulting in N round-trips to Redis.
21
+ # This version pipelines LLEN calls in batches to avoid blocking the Redis thread for too long,
22
+ # which is significantly faster when there are many delayed timestamps.
23
+ def count_all_scheduled_jobs_pipelined
24
+ timestamps = ::Resque.redis.zrange(:delayed_queue_schedule, 0, -1)
25
+ return 0 if timestamps.empty?
26
+
27
+ timestamps.each_slice(10_000).sum do |batch|
28
+ ::Resque.redis.pipelined do |pipeline|
29
+ batch.each { |ts| pipeline.llen("delayed:#{ts}") }
30
+ end.sum
31
+ end
32
+ end
33
+
34
+ def jobs_processing_oldest_age(config)
35
+ oldest_timestamp = ::Resque.working.map { |worker| worker.job(false)["run_at"] }.min
36
+ return 0 if oldest_timestamp.nil?
37
+ age_in_seconds = (Time.now - Time.parse(oldest_timestamp)).to_i
38
+ return 0 if age_in_seconds < 0
39
+
40
+ case config[:jobs_processing_oldest_age_unit]
41
+ when :seconds
42
+ age_in_seconds
43
+ when :minutes
44
+ age_in_seconds / 60.0
45
+ when :hours
46
+ age_in_seconds / 3600.0
47
+ when :days
48
+ age_in_seconds / 86_400.0
49
+ else
50
+ raise ArgumentError, "Unsupported time unit: #{unit.inspect}"
51
+ end
52
+ end
53
+
54
+ def install!(**config)
55
+ config = DEFAULT_CONFIG.merge(config)
56
+
16
57
  Yabeda.configure do
17
58
  group :resque do
18
59
  default_options = {aggregation: :most_recent}
@@ -20,6 +61,10 @@ module Yabeda
20
61
  gauge :jobs_processed, **default_options, comment: "Number of processed jobs"
21
62
  gauge :jobs_failed, **default_options, comment: "Number of failed jobs"
22
63
 
64
+ if config[:jobs_processing_oldest_age_unit]
65
+ gauge :jobs_processing_oldest_age, **default_options, comment: "How long the longest processing job has been running in #{config[:jobs_processing_oldest_age_unit]}"
66
+ end
67
+
23
68
  gauge :queue_sizes, tags: %i[queue], **default_options, comment: "Number of jobs in a specific queue"
24
69
 
25
70
  gauge :workers_total, **default_options, comment: "Number of workers"
@@ -37,8 +82,13 @@ module Yabeda
37
82
  resque.jobs_pending.set({}, resque_info[:pending])
38
83
  resque.jobs_processed.set({}, resque_info[:processed])
39
84
 
85
+ if config[:jobs_processing_oldest_age_unit]
86
+ value = ::Yabeda::Resque.jobs_processing_oldest_age(config)
87
+ resque.jobs_processing_oldest_age.set({}, value)
88
+ end
89
+
40
90
  if ::Yabeda::Resque.monitor_delayed?
41
- resque.jobs_delayed.set({}, ::Resque.count_all_scheduled_jobs)
91
+ resque.jobs_delayed.set({}, ::Yabeda::Resque.count_all_scheduled_jobs_pipelined)
42
92
  end
43
93
 
44
94
  ::Resque.queue_sizes.each do |queue, size|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josch Bockler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2026-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.5.11
80
+ rubygems_version: 3.5.22
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: Yabeda plugin to collect basic metrics for Resque backend jobs