rails-autoscale-good_job 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a537e5391508df4ceec83d4f3e5f0a46352acc56607e61637e506d122d4b27c
4
+ data.tar.gz: 593365c4b6af6247e511e7c0e014c7204890c511fb70bfe677ef17fc7b71ec87
5
+ SHA512:
6
+ metadata.gz: 4f8d693a9981a36f136512f3964d177a341d04136c4bec30400615ac589f8ae27ef2cdf098bbc4d2d6d0dcded1a3938173b0d79309ab10644b5614886855b93a
7
+ data.tar.gz: 99413e1a1302a68ebfdefca1f5fa36f1b995858b78d04b734479d6ddf83cc9eb2c48efbf5ac641c96aea12c10a057d538ec14b2c487dd74fd8bf10fa9bda2f7e
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec name: "judoscale-good_job"
4
+
5
+ gem "judoscale-ruby", path: "../judoscale-ruby"
6
+ gem "activerecord"
7
+ gem "pg"
8
+ gem "minitest"
9
+ gem "rake"
10
+ gem "rake-release"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec name: "judoscale-good_job"
4
+
5
+ gem "judoscale-ruby", path: "../judoscale-ruby"
6
+ gem "activerecord", "~> 6.1"
7
+ gem "pg"
8
+ gem "minitest"
9
+ gem "rake"
10
+ gem "rake-release"
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: ../judoscale-ruby
3
+ specs:
4
+ judoscale-ruby (1.3.0)
5
+
6
+ PATH
7
+ remote: .
8
+ specs:
9
+ judoscale-good_job (1.3.0)
10
+ good_job (>= 3.0)
11
+ judoscale-ruby (= 1.3.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actionpack (7.0.4.2)
17
+ actionview (= 7.0.4.2)
18
+ activesupport (= 7.0.4.2)
19
+ rack (~> 2.0, >= 2.2.0)
20
+ rack-test (>= 0.6.3)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
23
+ actionview (7.0.4.2)
24
+ activesupport (= 7.0.4.2)
25
+ builder (~> 3.1)
26
+ erubi (~> 1.4)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
29
+ activejob (7.0.4.2)
30
+ activesupport (= 7.0.4.2)
31
+ globalid (>= 0.3.6)
32
+ activemodel (7.0.4.2)
33
+ activesupport (= 7.0.4.2)
34
+ activerecord (7.0.4.2)
35
+ activemodel (= 7.0.4.2)
36
+ activesupport (= 7.0.4.2)
37
+ activesupport (7.0.4.2)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
39
+ i18n (>= 1.6, < 2)
40
+ minitest (>= 5.1)
41
+ tzinfo (~> 2.0)
42
+ builder (3.2.4)
43
+ concurrent-ruby (1.2.0)
44
+ crass (1.0.6)
45
+ erubi (1.12.0)
46
+ et-orbi (1.2.7)
47
+ tzinfo
48
+ fugit (1.8.1)
49
+ et-orbi (~> 1, >= 1.2.7)
50
+ raabro (~> 1.4)
51
+ globalid (1.1.0)
52
+ activesupport (>= 5.0)
53
+ good_job (3.12.1)
54
+ activejob (>= 6.0.0)
55
+ activerecord (>= 6.0.0)
56
+ concurrent-ruby (>= 1.0.2)
57
+ fugit (>= 1.1)
58
+ railties (>= 6.0.0)
59
+ thor (>= 0.14.1)
60
+ webrick (>= 1.3)
61
+ i18n (1.12.0)
62
+ concurrent-ruby (~> 1.0)
63
+ loofah (2.19.1)
64
+ crass (~> 1.0.2)
65
+ nokogiri (>= 1.5.9)
66
+ method_source (1.0.0)
67
+ minitest (5.17.0)
68
+ nokogiri (1.14.1-arm64-darwin)
69
+ racc (~> 1.4)
70
+ nokogiri (1.14.1-x86_64-linux)
71
+ racc (~> 1.4)
72
+ pg (1.4.5)
73
+ raabro (1.4.0)
74
+ racc (1.6.2)
75
+ rack (2.2.6.2)
76
+ rack-test (2.0.2)
77
+ rack (>= 1.3)
78
+ rails-dom-testing (2.0.3)
79
+ activesupport (>= 4.2.0)
80
+ nokogiri (>= 1.6)
81
+ rails-html-sanitizer (1.5.0)
82
+ loofah (~> 2.19, >= 2.19.1)
83
+ railties (7.0.4.2)
84
+ actionpack (= 7.0.4.2)
85
+ activesupport (= 7.0.4.2)
86
+ method_source
87
+ rake (>= 12.2)
88
+ thor (~> 1.0)
89
+ zeitwerk (~> 2.5)
90
+ rake (13.0.6)
91
+ rake-release (1.3.0)
92
+ bundler (>= 1.11, < 3)
93
+ thor (1.2.1)
94
+ tzinfo (2.0.6)
95
+ concurrent-ruby (~> 1.0)
96
+ webrick (1.8.1)
97
+ zeitwerk (2.6.6)
98
+
99
+ PLATFORMS
100
+ arm64-darwin-21
101
+ x86_64-linux
102
+
103
+ DEPENDENCIES
104
+ activerecord
105
+ judoscale-good_job!
106
+ judoscale-ruby!
107
+ minitest
108
+ pg
109
+ rake
110
+ rake-release
111
+
112
+ BUNDLED WITH
113
+ 2.3.9
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/release"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "lib"
8
+ t.libs << "test"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "judoscale/good_job/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "judoscale-good_job"
7
+ spec.version = Judoscale::GoodJob::VERSION
8
+ spec.authors = ["Adam McCrea", "Carlos Antonio da Silva"]
9
+ spec.email = ["adam@adamlogic.com"]
10
+
11
+ spec.summary = "This gem provides GoodJob integration with the Judoscale autoscaling add-on for Heroku."
12
+ spec.homepage = "https://judoscale.com"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata = {
16
+ "homepage_uri" => "https://judoscale.com",
17
+ "bug_tracker_uri" => "https://github.com/judoscale/judoscale-ruby/issues",
18
+ "documentation_uri" => "https://judoscale.com/docs",
19
+ "changelog_uri" => "https://github.com/judoscale/judoscale-ruby/blob/main/CHANGELOG.md",
20
+ "source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
21
+ }
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = ">= 2.6.0"
27
+
28
+ spec.add_dependency "judoscale-ruby", Judoscale::GoodJob::VERSION
29
+ spec.add_dependency "good_job", ">= 3.0"
30
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "judoscale/job_metrics_collector"
4
+ require "judoscale/job_metrics_collector/active_record_helper"
5
+ require "judoscale/metric"
6
+
7
+ module Judoscale
8
+ module GoodJob
9
+ class MetricsCollector < Judoscale::JobMetricsCollector
10
+ include ActiveRecordHelper
11
+
12
+ def self.adapter_config
13
+ Judoscale::Config.instance.good_job
14
+ end
15
+
16
+ def initialize
17
+ super
18
+
19
+ queue_names = run_silently do
20
+ ::GoodJob::Execution.select("distinct queue_name").map(&:queue_name)
21
+ end
22
+ self.queues |= queue_names
23
+ end
24
+
25
+ def collect
26
+ metrics = []
27
+ time = Time.now.utc
28
+
29
+ # logically we don't need the finished_at condition, but it lets postgres use the indexes
30
+ oldest_execution_time_by_queue = run_silently do
31
+ ::GoodJob::Execution
32
+ .where(performed_at: nil, finished_at: nil)
33
+ .group(:queue_name)
34
+ .pluck(:queue_name, Arel.sql("min(coalesce(scheduled_at, created_at))"))
35
+ .to_h
36
+ end
37
+ self.queues |= oldest_execution_time_by_queue.keys
38
+
39
+ if track_busy_jobs?
40
+ busy_count_by_queue = run_silently do
41
+ ::GoodJob::Execution.running.group(:queue_name).count
42
+ end
43
+ self.queues |= busy_count_by_queue.keys
44
+ end
45
+
46
+ queues.each do |queue|
47
+ run_at = oldest_execution_time_by_queue[queue]
48
+ # DateTime.parse assumes a UTC string
49
+ run_at = DateTime.parse(run_at) if run_at.is_a?(String)
50
+ latency_ms = run_at ? ((time - run_at) * 1000).ceil : 0
51
+ latency_ms = 0 if latency_ms < 0
52
+
53
+ metrics.push Metric.new(:qt, latency_ms, time, queue)
54
+
55
+ if track_busy_jobs?
56
+ busy_count = busy_count_by_queue[queue] || 0
57
+ metrics.push Metric.new(:busy, busy_count, Time.now, queue)
58
+ end
59
+ end
60
+
61
+ log_collection(metrics)
62
+ metrics
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Judoscale
4
+ module GoodJob
5
+ VERSION = "1.3.0"
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require "good_job" fails unless we require these first
4
+ require "rails"
5
+ require "active_support/core_ext/numeric/time"
6
+ require "active_job/railtie"
7
+ require "good_job"
8
+ require "judoscale-ruby"
9
+ require "judoscale/config"
10
+ require "judoscale/good_job/version"
11
+ require "judoscale/good_job/metrics_collector"
12
+
13
+ Judoscale.add_adapter :"judoscale-good_job",
14
+ {
15
+ adapter_version: Judoscale::GoodJob::VERSION,
16
+ framework_version: ::GoodJob::VERSION
17
+ },
18
+ metrics_collector: Judoscale::GoodJob::MetricsCollector,
19
+ expose_config: Judoscale::Config::JobAdapterConfig.new(:good_job)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "judoscale/good_job"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "judoscale/good_job"
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "judoscale/good_job/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rails-autoscale-good_job"
7
+ spec.version = Judoscale::GoodJob::VERSION
8
+ spec.authors = ["Adam McCrea", "Carlos Antonio da Silva"]
9
+ spec.email = ["adam@adamlogic.com"]
10
+
11
+ spec.summary = "This gem provides GoodJob integration with the Judoscale autoscaling add-on for Heroku."
12
+ spec.homepage = "https://judoscale.com"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata = {
16
+ "homepage_uri" => "https://judoscale.com",
17
+ "bug_tracker_uri" => "https://github.com/judoscale/judoscale-ruby/issues",
18
+ "documentation_uri" => "https://judoscale.com/docs",
19
+ "changelog_uri" => "https://github.com/judoscale/judoscale-ruby/blob/main/CHANGELOG.md",
20
+ "source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
21
+ }
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = ">= 2.6.0"
27
+
28
+ spec.add_dependency "rails-autoscale-core", Judoscale::GoodJob::VERSION
29
+ spec.add_dependency "good_job_active_record", ">= 4.0"
30
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-autoscale-good_job
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam McCrea
8
+ - Carlos Antonio da Silva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2023-02-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails-autoscale-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.3.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.3.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: good_job_active_record
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '4.0'
42
+ description:
43
+ email:
44
+ - adam@adamlogic.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - Gemfile-activerecord-6-1
51
+ - Gemfile.lock
52
+ - Rakefile
53
+ - judoscale-good_job.gemspec
54
+ - lib/judoscale-good_job.rb
55
+ - lib/judoscale/good_job.rb
56
+ - lib/judoscale/good_job/metrics_collector.rb
57
+ - lib/judoscale/good_job/version.rb
58
+ - lib/rails-autoscale-good_job.rb
59
+ - rails-autoscale-good_job.gemspec
60
+ homepage: https://judoscale.com
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ homepage_uri: https://judoscale.com
65
+ bug_tracker_uri: https://github.com/judoscale/judoscale-ruby/issues
66
+ documentation_uri: https://judoscale.com/docs
67
+ changelog_uri: https://github.com/judoscale/judoscale-ruby/blob/main/CHANGELOG.md
68
+ source_code_uri: https://github.com/judoscale/judoscale-ruby
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.2.32
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: This gem provides GoodJob integration with the Judoscale autoscaling add-on
88
+ for Heroku.
89
+ test_files: []