From 01aea0106d05251e533a64be5e8af6125e334724 Mon Sep 17 00:00:00 2001 From: Michael van Rooijen Date: Fri, 26 Jul 2024 17:12:09 +0800 Subject: [PATCH] Add support for Good Job v4 --- Appraisals | 6 + Rakefile | 2 +- gemfiles/good_job_4.gemfile | 20 ++ gemfiles/good_job_4.gemfile.lock | 291 ++++++++++++++++++ lib/hirefire/macro/deprecated/good_job.rb | 7 +- lib/hirefire/macro/good_job.rb | 8 +- lib/hirefire/macro/helpers/good_job.rb | 19 ++ test/env/rails_good_job_4/.gitignore | 1 + test/env/rails_good_job_4/Rakefile | 3 + .../rails_good_job_4/app/jobs/basic_job.rb | 4 + test/env/rails_good_job_4/bin/rails | 4 + test/env/rails_good_job_4/config.ru | 2 + .../rails_good_job_4/config/application.rb | 13 + test/env/rails_good_job_4/config/boot.rb | 3 + test/env/rails_good_job_4/config/database.yml | 6 + .../rails_good_job_4/config/environment.rb | 2 + .../20231021073152_create_good_jobs.rb | 102 ++++++ test/hirefire/macro/test_good_job.rb | 16 +- 18 files changed, 495 insertions(+), 14 deletions(-) create mode 100644 gemfiles/good_job_4.gemfile create mode 100644 gemfiles/good_job_4.gemfile.lock create mode 100644 lib/hirefire/macro/helpers/good_job.rb create mode 100644 test/env/rails_good_job_4/.gitignore create mode 100644 test/env/rails_good_job_4/Rakefile create mode 100644 test/env/rails_good_job_4/app/jobs/basic_job.rb create mode 100755 test/env/rails_good_job_4/bin/rails create mode 100644 test/env/rails_good_job_4/config.ru create mode 100644 test/env/rails_good_job_4/config/application.rb create mode 100644 test/env/rails_good_job_4/config/boot.rb create mode 100644 test/env/rails_good_job_4/config/database.yml create mode 100644 test/env/rails_good_job_4/config/environment.rb create mode 100644 test/env/rails_good_job_4/db/migrate/20231021073152_create_good_jobs.rb diff --git a/Appraisals b/Appraisals index 0d0f8e6..86c61af 100644 --- a/Appraisals +++ b/Appraisals @@ -30,6 +30,12 @@ appraise "good_job_3" do gem "good_job", "~> 3", require: false end +appraise "good_job_4" do + gem "pg" + gem "rails", "~> 7" + gem "good_job", "~> 4", require: false +end + appraise "queue_classic_4" do gem "pg" gem "rails", "~> 7" diff --git a/Rakefile b/Rakefile index 7efa67b..da5770e 100644 --- a/Rakefile +++ b/Rakefile @@ -48,7 +48,7 @@ APPRAISAL_VERSIONS = { "solid_queue" => %w[0], "sidekiq" => %w[6 7], "bunny" => %w[2], - "good_job" => %w[2 3], + "good_job" => %w[2 3 4], "delayed_job_active_record" => %w[4], "delayed_job_mongoid" => %w[3], "queue_classic" => %w[4], diff --git a/gemfiles/good_job_4.gemfile b/gemfiles/good_job_4.gemfile new file mode 100644 index 0000000..b8bc087 --- /dev/null +++ b/gemfiles/good_job_4.gemfile @@ -0,0 +1,20 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "debug" +gem "rake" +gem "standardrb" +gem "minitest" +gem "webmock" +gem "mocha" +gem "timecop" +gem "yard" +gem "rack" +gem "webrick" +gem "simplecov", require: false +gem "pg" +gem "rails", "~> 7" +gem "good_job", "~> 4", require: false + +gemspec path: "../" diff --git a/gemfiles/good_job_4.gemfile.lock b/gemfiles/good_job_4.gemfile.lock new file mode 100644 index 0000000..11e9d3b --- /dev/null +++ b/gemfiles/good_job_4.gemfile.lock @@ -0,0 +1,291 @@ +PATH + remote: .. + specs: + hirefire-resource (1.0.3) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.4) + actionpack (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activesupport (= 7.1.3.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.4) + actionview (= 7.1.3.4) + activesupport (= 7.1.3.4) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.4) + actionpack (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.3.4) + activesupport (= 7.1.3.4) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3.4) + activesupport (= 7.1.3.4) + globalid (>= 0.3.6) + activemodel (7.1.3.4) + activesupport (= 7.1.3.4) + activerecord (7.1.3.4) + activemodel (= 7.1.3.4) + activesupport (= 7.1.3.4) + timeout (>= 0.4.0) + activestorage (7.1.3.4) + actionpack (= 7.1.3.4) + activejob (= 7.1.3.4) + activerecord (= 7.1.3.4) + activesupport (= 7.1.3.4) + marcel (~> 1.0) + activesupport (7.1.3.4) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.8) + builder (3.3.0) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + date (3.3.4) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + docile (1.4.0) + drb (2.2.1) + erubi (1.13.0) + et-orbi (1.2.11) + tzinfo + fugit (1.11.0) + et-orbi (~> 1, >= 1.2.11) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) + good_job (4.1.0) + activejob (>= 6.1.0) + activerecord (>= 6.1.0) + concurrent-ruby (>= 1.3.1) + fugit (>= 1.11.0) + railties (>= 6.1.0) + thor (>= 1.0.0) + hashdiff (1.1.0) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + mini_mime (1.1.5) + minitest (5.24.1) + mocha (2.3.0) + ruby2_keywords (>= 0.0.5) + mutex_m (0.2.0) + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.3) + nokogiri (1.16.6-arm64-darwin) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.2.0) + ast (~> 2.4.1) + racc + pg (1.5.6) + psych (5.1.2) + stringio + public_suffix (6.0.1) + raabro (1.4.0) + racc (1.8.0) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3.4) + actioncable (= 7.1.3.4) + actionmailbox (= 7.1.3.4) + actionmailer (= 7.1.3.4) + actionpack (= 7.1.3.4) + actiontext (= 7.1.3.4) + actionview (= 7.1.3.4) + activejob (= 7.1.3.4) + activemodel (= 7.1.3.4) + activerecord (= 7.1.3.4) + activestorage (= 7.1.3.4) + activesupport (= 7.1.3.4) + bundler (>= 1.15.0) + railties (= 7.1.3.4) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3.4) + actionpack (= 7.1.3.4) + activesupport (= 7.1.3.4) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) + io-console (~> 0.5) + rexml (3.3.2) + strscan + rubocop (1.63.5) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + standard (1.36.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.63.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + standardrb (1.0.1) + standard + stringio (3.1.1) + strscan (3.1.0) + thor (1.3.1) + timecop (0.9.8) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + webmock (3.23.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.8.1) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + yard (0.9.36) + zeitwerk (2.6.16) + +PLATFORMS + arm64-darwin-23 + +DEPENDENCIES + appraisal (~> 2) + debug + good_job (~> 4) + hirefire-resource! + minitest + mocha + pg + rack + rails (~> 7) + rake + simplecov + standardrb + timecop + webmock + webrick + yard + +BUNDLED WITH + 2.4.7 diff --git a/lib/hirefire/macro/deprecated/good_job.rb b/lib/hirefire/macro/deprecated/good_job.rb index 64db9e0..03b4db6 100644 --- a/lib/hirefire/macro/deprecated/good_job.rb +++ b/lib/hirefire/macro/deprecated/good_job.rb @@ -1,11 +1,15 @@ # frozen_string_literal: true +require "hirefire/macro/helpers/good_job" + module HireFire module Macro module Deprecated # Provides backward compatibility with the deprecated GoodJob macro. # For new implementations, refer to {HireFire::Macro::GoodJob}. module GoodJob + include HireFire::Macro::Helpers::GoodJob + # Retrieves the total number of jobs in the specified queue(s) using GoodJob. # # This method queries the PostgreSQL database through GoodJob. It's capable @@ -21,8 +25,7 @@ module GoodJob # @example Counting jobs in the "default" queue # HireFire::Macro::GoodJob.queue("default") def queue(*queues) - base_class = defined?(::GoodJob::Execution) ? ::GoodJob::Execution : ::GoodJob::Job - scope = base_class.only_scheduled.unfinished + scope = good_job_class.only_scheduled.unfinished scope = scope.where(queue_name: queues) if queues.any? scope.count end diff --git a/lib/hirefire/macro/good_job.rb b/lib/hirefire/macro/good_job.rb index 61e33e3..bf3fe82 100644 --- a/lib/hirefire/macro/good_job.rb +++ b/lib/hirefire/macro/good_job.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true +require_relative "helpers/good_job" require_relative "deprecated/good_job" module HireFire module Macro module GoodJob - extend HireFire::Macro::Deprecated::GoodJob extend HireFire::Utility + extend HireFire::Macro::Helpers::GoodJob + extend HireFire::Macro::Deprecated::GoodJob extend self # Calculates the maximum job queue latency using GoodJob. If no queues are specified, it @@ -23,7 +25,7 @@ module GoodJob # HireFire::Macro::GoodJob.job_queue_latency(:default, :mailer) def job_queue_latency(*queues) queues = normalize_queues(queues, allow_empty: true) - query = ::GoodJob::Execution + query = good_job_class query = query.where(queue_name: queues) if queues.any? query = query.where(performed_at: nil) query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil)) @@ -50,7 +52,7 @@ def job_queue_latency(*queues) # HireFire::Macro::GoodJob.job_queue_size(:default, :mailer) def job_queue_size(*queues) queues = normalize_queues(queues, allow_empty: true) - query = ::GoodJob::Execution + query = good_job_class query = query.where(queue_name: queues) if queues.any? query = query.where(performed_at: nil) query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil)) diff --git a/lib/hirefire/macro/helpers/good_job.rb b/lib/hirefire/macro/helpers/good_job.rb new file mode 100644 index 0000000..64f2815 --- /dev/null +++ b/lib/hirefire/macro/helpers/good_job.rb @@ -0,0 +1,19 @@ +module HireFire + module Macro + module Helpers + module GoodJob + def self.included(base) + base.send(:private, :good_job_class) + end + + def good_job_class + if Gem::Version.new(::GoodJob::VERSION) >= Gem::Version.new("4.0.0") + ::GoodJob::Job + else + ::GoodJob::Execution + end + end + end + end + end +end diff --git a/test/env/rails_good_job_4/.gitignore b/test/env/rails_good_job_4/.gitignore new file mode 100644 index 0000000..cad2309 --- /dev/null +++ b/test/env/rails_good_job_4/.gitignore @@ -0,0 +1 @@ +/tmp \ No newline at end of file diff --git a/test/env/rails_good_job_4/Rakefile b/test/env/rails_good_job_4/Rakefile new file mode 100644 index 0000000..d1baef0 --- /dev/null +++ b/test/env/rails_good_job_4/Rakefile @@ -0,0 +1,3 @@ +require_relative "config/application" + +Rails.application.load_tasks diff --git a/test/env/rails_good_job_4/app/jobs/basic_job.rb b/test/env/rails_good_job_4/app/jobs/basic_job.rb new file mode 100644 index 0000000..d1522f9 --- /dev/null +++ b/test/env/rails_good_job_4/app/jobs/basic_job.rb @@ -0,0 +1,4 @@ +class BasicJob < ActiveJob::Base + def perform + end +end diff --git a/test/env/rails_good_job_4/bin/rails b/test/env/rails_good_job_4/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/test/env/rails_good_job_4/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/test/env/rails_good_job_4/config.ru b/test/env/rails_good_job_4/config.ru new file mode 100644 index 0000000..cb0bc69 --- /dev/null +++ b/test/env/rails_good_job_4/config.ru @@ -0,0 +1,2 @@ +require_relative "config/environment" +run Rails.application diff --git a/test/env/rails_good_job_4/config/application.rb b/test/env/rails_good_job_4/config/application.rb new file mode 100644 index 0000000..861fa98 --- /dev/null +++ b/test/env/rails_good_job_4/config/application.rb @@ -0,0 +1,13 @@ +require_relative "boot" + +require "active_job/railtie" +require "active_record/railtie" +require "good_job" + +class RailsGoodJob4Application < Rails::Application + config.load_defaults 7.0 + config.root = File.expand_path("../..", __FILE__) + config.eager_load = false + config.active_job.queue_adapter = :good_job + config.good_job.execution_mode = :external +end diff --git a/test/env/rails_good_job_4/config/boot.rb b/test/env/rails_good_job_4/config/boot.rb new file mode 100644 index 0000000..ef2741d --- /dev/null +++ b/test/env/rails_good_job_4/config/boot.rb @@ -0,0 +1,3 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../gemfiles/good_job_4.gemfile", __dir__) + +require "bundler/setup" diff --git a/test/env/rails_good_job_4/config/database.yml b/test/env/rails_good_job_4/config/database.yml new file mode 100644 index 0000000..2843e5b --- /dev/null +++ b/test/env/rails_good_job_4/config/database.yml @@ -0,0 +1,6 @@ +test: + adapter: postgresql + host: localhost + database: rails_good_job_4_test_database + username: <%= ENV["POSTGRES_USER"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> diff --git a/test/env/rails_good_job_4/config/environment.rb b/test/env/rails_good_job_4/config/environment.rb new file mode 100644 index 0000000..40c19d2 --- /dev/null +++ b/test/env/rails_good_job_4/config/environment.rb @@ -0,0 +1,2 @@ +require_relative "application" +Rails.application.initialize! diff --git a/test/env/rails_good_job_4/db/migrate/20231021073152_create_good_jobs.rb b/test/env/rails_good_job_4/db/migrate/20231021073152_create_good_jobs.rb new file mode 100644 index 0000000..2dc7ea6 --- /dev/null +++ b/test/env/rails_good_job_4/db/migrate/20231021073152_create_good_jobs.rb @@ -0,0 +1,102 @@ +# frozen_string_literal: true + +class CreateGoodJobs < ActiveRecord::Migration[7.1] + def change + # Uncomment for Postgres v12 or earlier to enable gen_random_uuid() support + # enable_extension 'pgcrypto' + + create_table :good_jobs, id: :uuid do |t| + t.text :queue_name + t.integer :priority + t.jsonb :serialized_params + t.datetime :scheduled_at + t.datetime :performed_at + t.datetime :finished_at + t.text :error + + t.timestamps + + t.uuid :active_job_id + t.text :concurrency_key + t.text :cron_key + t.uuid :retried_good_job_id + t.datetime :cron_at + + t.uuid :batch_id + t.uuid :batch_callback_id + + t.boolean :is_discrete + t.integer :executions_count + t.text :job_class + t.integer :error_event, limit: 2 + t.text :labels, array: true + t.uuid :locked_by_id + t.datetime :locked_at + end + + create_table :good_job_batches, id: :uuid do |t| + t.timestamps + t.text :description + t.jsonb :serialized_properties + t.text :on_finish + t.text :on_success + t.text :on_discard + t.text :callback_queue_name + t.integer :callback_priority + t.datetime :enqueued_at + t.datetime :discarded_at + t.datetime :finished_at + end + + create_table :good_job_executions, id: :uuid do |t| + t.timestamps + + t.uuid :active_job_id, null: false + t.text :job_class + t.text :queue_name + t.jsonb :serialized_params + t.datetime :scheduled_at + t.datetime :finished_at + t.text :error + t.integer :error_event, limit: 2 + t.text :error_backtrace, array: true + t.uuid :process_id + t.interval :duration + end + + create_table :good_job_processes, id: :uuid do |t| + t.timestamps + t.jsonb :state + t.integer :lock_type, limit: 2 + end + + create_table :good_job_settings, id: :uuid do |t| + t.timestamps + t.text :key + t.jsonb :value + t.index :key, unique: true + end + + add_index :good_jobs, :scheduled_at, where: "(finished_at IS NULL)", name: :index_good_jobs_on_scheduled_at + add_index :good_jobs, [:queue_name, :scheduled_at], where: "(finished_at IS NULL)", name: :index_good_jobs_on_queue_name_and_scheduled_at + add_index :good_jobs, [:active_job_id, :created_at], name: :index_good_jobs_on_active_job_id_and_created_at + add_index :good_jobs, :concurrency_key, where: "(finished_at IS NULL)", name: :index_good_jobs_on_concurrency_key_when_unfinished + add_index :good_jobs, [:cron_key, :created_at], where: "(cron_key IS NOT NULL)", name: :index_good_jobs_on_cron_key_and_created_at_cond + add_index :good_jobs, [:cron_key, :cron_at], where: "(cron_key IS NOT NULL)", unique: true, name: :index_good_jobs_on_cron_key_and_cron_at_cond + add_index :good_jobs, [:finished_at], where: "retried_good_job_id IS NULL AND finished_at IS NOT NULL", name: :index_good_jobs_jobs_on_finished_at + add_index :good_jobs, [:priority, :created_at], order: {priority: "DESC NULLS LAST", created_at: :asc}, + where: "finished_at IS NULL", name: :index_good_jobs_jobs_on_priority_created_at_when_unfinished + add_index :good_jobs, [:priority, :created_at], order: {priority: "ASC NULLS LAST", created_at: :asc}, + where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup + add_index :good_jobs, [:batch_id], where: "batch_id IS NOT NULL" + add_index :good_jobs, [:batch_callback_id], where: "batch_callback_id IS NOT NULL" + add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)", name: :index_good_jobs_on_labels + + add_index :good_job_executions, [:active_job_id, :created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + add_index :good_jobs, [:priority, :scheduled_at], order: {priority: "ASC NULLS LAST", scheduled_at: :asc}, + where: "finished_at IS NULL AND locked_by_id IS NULL", name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked + add_index :good_jobs, :locked_by_id, + where: "locked_by_id IS NOT NULL", name: "index_good_jobs_on_locked_by_id" + add_index :good_job_executions, [:process_id, :created_at], name: :index_good_job_executions_on_process_id_and_created_at + end +end diff --git a/test/hirefire/macro/test_good_job.rb b/test/hirefire/macro/test_good_job.rb index f2bd412..2c618a5 100644 --- a/test/hirefire/macro/test_good_job.rb +++ b/test/hirefire/macro/test_good_job.rb @@ -2,14 +2,14 @@ require "test_helper" require "good_job/version" +require "hirefire/macro/helpers/good_job" -if Gem::Version.new(::GoodJob::VERSION) >= Gem::Version.new("3.0.0") - require_relative "../../env/rails_good_job_3/config/environment" -else - require_relative "../../env/rails_good_job_2/config/environment" -end +major_version = Gem::Version.new(::GoodJob::VERSION).segments[0] +require_relative "../../env/rails_good_job_#{major_version}/config/environment" class HireFire::Macro::GoodJobTest < Minitest::Test + include HireFire::Macro::Helpers::GoodJob + LATENCY_DELTA = 2 def setup @@ -38,7 +38,7 @@ def test_job_queue_latency_with_scheduled_job def test_job_queue_latency_with_unfinished_jobs job_id = Timecop.freeze(1.minute.ago) { BasicJob.perform_later.job_id } - GoodJob::Execution.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) + good_job_class.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) assert_equal 0, HireFire::Macro::GoodJob.job_queue_latency end @@ -62,7 +62,7 @@ def test_job_queue_size_with_scheduled_jobs def test_job_queue_size_with_unfinished_jobs job_id = BasicJob.perform_later.job_id - GoodJob::Execution.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) + good_job_class.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) assert_equal 0, HireFire::Macro::GoodJob.job_queue_size end @@ -88,6 +88,6 @@ def prepare_database ActiveRecord::Migration.verbose = false ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate").to_s).migrate - GoodJob::Execution.delete_all + good_job_class.delete_all end end