judoscale-resque 1.14.0 → 1.16.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: 9bb4a04727177c87bf91f37ffdf23755a7fd4e44a40c721b4b813217e3d3947d
4
- data.tar.gz: df9a2a7c245cbafde636fe0278e5c0e3be998d46008319c778ac8b332688c941
3
+ metadata.gz: 26a5ce1ac63f8523dc260ece587081dbd46a76ce4b9ca5330f7020c697d582cc
4
+ data.tar.gz: 52e2fab30da5972097ba3cd3623442c80019619b71b633f143137291678c3c55
5
5
  SHA512:
6
- metadata.gz: 464b5cf2a1cddf2b1d4f973b4902184f321f5fcab56bb968204758cfa21d445e4bbeae2e0407dd0dbb90e6b4aee0b193eefbdd42c35e06f6edd9aa070e7433ee
7
- data.tar.gz: 1b3a9a9b82f9c5a83eaf1a2e9591edf1d763c28271fdbfa46369f2d7c45ae1b8bd7be882b5e261b2d3d23dc8ebd4a2914aa112ca35655c4b8302252b31593115
6
+ metadata.gz: adb0b2cbfb9160795b7edc076c7b42a56955434135055a5c84131af38d456aa4fca19fdb311cbe22644907b4ee1bcf322fd650ddad5c309eafcefe90b5b0386b
7
+ data.tar.gz: 0702bbbcdc52d547fe21094d8739c530c484de374e3d6f166e1905e61a4e09af5bd7b5b37699348371b023ffb35e1fc48cc89a821aa7424fd8510e520e207cf9
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "judoscale/job_metrics_collector"
4
4
  require "judoscale/metric"
5
+ require "time"
5
6
 
6
7
  module Judoscale
7
8
  module Resque
@@ -17,11 +18,17 @@ module Judoscale
17
18
 
18
19
  if track_busy_jobs?
19
20
  busy_counts = Hash.new { |h, k| h[k] = 0 }
21
+ oldest_run_at_by_queue = {}
20
22
 
23
+ # `Resque.working` reads every worker's job in one call and skips idle workers. `job(false)` uses
24
+ # that job instead of fetching it again, which would cost a Redis round trip per busy worker.
21
25
  ::Resque.working.each do |worker|
22
- if !worker.idle? && (job = worker.job)
23
- busy_counts[job["queue"]] += 1
24
- end
26
+ job = worker.job(false)
27
+ queue = job["queue"]
28
+ run_at = Time.iso8601(job["run_at"])
29
+ busy_counts[queue] += 1
30
+ oldest_run_at = oldest_run_at_by_queue[queue]
31
+ oldest_run_at_by_queue[queue] = run_at if oldest_run_at.nil? || run_at < oldest_run_at
25
32
  end
26
33
  end
27
34
 
@@ -38,6 +45,11 @@ module Judoscale
38
45
  if track_busy_jobs?
39
46
  busy_count = busy_counts[queue]
40
47
  metrics.push Metric.new(:busy, busy_count, time, queue)
48
+
49
+ run_at = oldest_run_at_by_queue[queue]
50
+ busy_time_ms = run_at ? ((time - run_at) * 1000).ceil : 0
51
+ busy_time_ms = 0 if busy_time_ms < 0
52
+ metrics.push Metric.new(:bt, busy_time_ms, time, queue)
41
53
  end
42
54
  end
43
55
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judoscale-resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam McCrea
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.14.0
20
+ version: 1.16.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.14.0
27
+ version: 1.16.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: resque
30
30
  requirement: !ruby/object:Gem::Requirement