├── .rspec ├── gemfiles ├── .rubocop.yml ├── mysql2 │ ├── 3-1.gemfile │ ├── 3-2.gemfile │ ├── 4-0.gemfile │ ├── 4-1.gemfile │ ├── 3-0.gemfile │ ├── 7-1.gemfile │ ├── 7-2.gemfile │ ├── 8-0.gemfile │ ├── 5-2.gemfile │ ├── 5-0.gemfile │ ├── 5-1.gemfile │ ├── 4-2.gemfile │ ├── 6-0.gemfile │ ├── 6-1.gemfile │ ├── 7-0.gemfile │ └── master.gemfile ├── postgresql │ ├── 3-0.gemfile │ ├── 3-1.gemfile │ ├── 3-2.gemfile │ ├── 4-0.gemfile │ ├── 4-1.gemfile │ ├── 7-1.gemfile │ ├── 7-2.gemfile │ ├── 8-0.gemfile │ ├── 4-2.gemfile │ ├── 5-0.gemfile │ ├── 5-1.gemfile │ ├── 5-2.gemfile │ ├── 6-1.gemfile │ ├── 7-0.gemfile │ ├── 6-0.gemfile │ └── master.gemfile ├── sqlite3 │ ├── 3-0.gemfile │ ├── 3-1.gemfile │ ├── 3-2.gemfile │ ├── 4-0.gemfile │ ├── 4-1.gemfile │ ├── 7-1.gemfile │ ├── 7-2.gemfile │ ├── 8-0.gemfile │ ├── 5-0.gemfile │ ├── 4-2.gemfile │ ├── 5-1.gemfile │ ├── 5-2.gemfile │ ├── 6-0.gemfile │ ├── 6-1.gemfile │ ├── 7-0.gemfile │ └── master.gemfile └── trilogy │ ├── 7-1.gemfile │ ├── 7-2.gemfile │ ├── 8-0.gemfile │ ├── master.gemfile │ ├── 6-0.gemfile │ ├── 6-1.gemfile │ └── 7-0.gemfile ├── .gitignore ├── lib ├── delayed_job_active_record.rb ├── generators │ └── delayed_job │ │ ├── templates │ │ ├── upgrade_migration.rb │ │ └── migration.rb │ │ ├── upgrade_generator.rb │ │ ├── next_migration_version.rb │ │ └── active_record_generator.rb └── delayed │ └── backend │ └── active_record.rb ├── spec ├── .rubocop.yml ├── delayed │ ├── serialization │ │ └── active_record_spec.rb │ └── backend │ │ └── active_record_spec.rb ├── database.yml └── helper.rb ├── .github └── workflows │ ├── publish_gem.yml │ ├── rubocop.yml │ ├── canary.yml │ └── ci.yml ├── CONTRIBUTING.md ├── Gemfile ├── Rakefile ├── delayed_job_active_record.gemspec ├── LICENSE.md ├── README.md └── .rubocop.yml /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --fail-fast 3 | -------------------------------------------------------------------------------- /gemfiles/.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: 2 | - ../.rubocop.yml 3 | 4 | Naming/FileName: 5 | Enabled: false 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .bundle 3 | .rvmrc 4 | Gemfile.lock 5 | bin 6 | coverage 7 | pkg/* 8 | gemfiles/**/*.gemfile.lock 9 | -------------------------------------------------------------------------------- /lib/delayed_job_active_record.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "active_record" 4 | require "delayed_job" 5 | require "delayed/backend/active_record" 6 | 7 | Delayed::Worker.backend = :active_record 8 | -------------------------------------------------------------------------------- /spec/.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: 2 | - ../.rubocop.yml 3 | 4 | Lint/AmbiguousBlockAssociation: 5 | Enabled: false 6 | 7 | Metrics/BlockLength: 8 | Enabled: false 9 | 10 | RSpec/ContextWording: 11 | Enabled: false 12 | 13 | Rails/FilePath: 14 | Enabled: false 15 | -------------------------------------------------------------------------------- /lib/generators/delayed_job/templates/upgrade_migration.rb: -------------------------------------------------------------------------------- 1 | class AddQueueToDelayedJobs < ActiveRecord::Migration<%= migration_version %> 2 | def self.up 3 | add_column :delayed_jobs, :queue, :string 4 | end 5 | 6 | def self.down 7 | remove_column :delayed_jobs, :queue 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /gemfiles/mysql2/3-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | gem "mysql2", "~> 0.3.10" 8 | 9 | gem "rspec", ">= 2.11" 10 | gem "simplecov", ">= 0.17.0", require: false 11 | gem "simplecov-lcov", "< 0.8.0", require: false 12 | 13 | gem "activerecord", "~> 3.1.0" 14 | 15 | gemspec path: "../../" 16 | -------------------------------------------------------------------------------- /gemfiles/mysql2/3-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | gem "mysql2", "~> 0.3.10" 8 | 9 | gem "rspec", ">= 2.11" 10 | gem "simplecov", ">= 0.17.0", require: false 11 | gem "simplecov-lcov", "< 0.8.0", require: false 12 | 13 | gem "activerecord", "~> 3.2.0" 14 | 15 | gemspec path: "../../" 16 | -------------------------------------------------------------------------------- /gemfiles/mysql2/4-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | gem "mysql2", "~> 0.3.10" 8 | 9 | gem "rspec", ">= 2.11" 10 | gem "simplecov", ">= 0.17.0", require: false 11 | gem "simplecov-lcov", "< 0.8.0", require: false 12 | 13 | gem "activerecord", "~> 4.0.0" 14 | 15 | gemspec path: "../../" 16 | -------------------------------------------------------------------------------- /gemfiles/mysql2/4-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | gem "mysql2", "~> 0.3.13" 8 | 9 | gem "rspec", ">= 2.11" 10 | gem "simplecov", ">= 0.17.0", require: false 11 | gem "simplecov-lcov", "< 0.8.0", require: false 12 | 13 | gem "activerecord", "~> 4.1.0" 14 | 15 | gemspec path: "../../" 16 | -------------------------------------------------------------------------------- /gemfiles/postgresql/3-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "pg", "~> 0.18" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.0.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/postgresql/3-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "pg", "~> 0.18" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.1.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/postgresql/3-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "pg", "~> 0.18" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.2.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/postgresql/4-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "pg", "~> 0.18" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 4.0.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/postgresql/4-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "pg", "~> 0.18" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 4.1.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/3-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "sqlite3", "< 1.4" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.0.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/3-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "sqlite3", "< 1.4" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.1.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/3-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "sqlite3", "< 1.4" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.2.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/4-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "sqlite3", "< 1.4" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 4.0.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/4-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "sqlite3", "< 1.4" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 4.1.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/mysql2/3-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | gem "activerecord-mysql2-adapter" 9 | 10 | gem "rspec", ">= 2.11" 11 | gem "simplecov", ">= 0.17.0", require: false 12 | gem "simplecov-lcov", "< 0.8.0", require: false 13 | 14 | gem "activerecord", "~> 3.0.0" 15 | end 16 | 17 | gemspec path: "../../" 18 | -------------------------------------------------------------------------------- /gemfiles/trilogy/7-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "trilogy", "~> 2.4" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 7.1.0" 17 | end 18 | 19 | gemspec path: "../../" 20 | -------------------------------------------------------------------------------- /gemfiles/trilogy/7-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "trilogy", "~> 2.7" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 7.2.0" 17 | end 18 | 19 | gemspec path: "../../" 20 | -------------------------------------------------------------------------------- /gemfiles/trilogy/8-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "trilogy", "~> 2.7" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 8.0.0" 17 | end 18 | 19 | gemspec path: "../../" 20 | -------------------------------------------------------------------------------- /spec/delayed/serialization/active_record_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "helper" 4 | 5 | describe ActiveRecord do 6 | it "loads classes with non-default primary key" do 7 | expect do 8 | YAML.load_dj(Story.create.to_yaml) 9 | end.not_to raise_error 10 | end 11 | 12 | it "loads classes even if not in default scope" do 13 | expect do 14 | YAML.load_dj(Story.create(scoped: false).to_yaml) 15 | end.not_to raise_error 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /gemfiles/trilogy/master.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "trilogy" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", github: "rails" 17 | end 18 | 19 | gem "delayed_job", github: "collectiveidea/delayed_job" 20 | 21 | gemspec path: "../../" 22 | -------------------------------------------------------------------------------- /gemfiles/trilogy/6-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "activerecord-trilogy-adapter" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 6.0.0" 17 | 18 | gem "base64" 19 | gem "bigdecimal" 20 | gem "mutex_m" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/trilogy/6-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "activerecord-trilogy-adapter" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 6.1.0" 17 | 18 | gem "base64" 19 | gem "bigdecimal" 20 | gem "mutex_m" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/trilogy/7-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :ruby, :mswin, :mingw do 9 | gem "activerecord-trilogy-adapter" 10 | end 11 | 12 | gem "rspec", ">= 2.11" 13 | gem "simplecov", ">= 0.20.0", require: false 14 | gem "simplecov-lcov", ">= 0.8.0", require: false 15 | 16 | gem "activerecord", "~> 7.0.1" 17 | 18 | gem "base64" 19 | gem "bigdecimal" 20 | gem "mutex_m" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/7-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", "~> 0.5" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/7-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", "~> 0.5" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/8-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", "~> 0.5" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 8.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/7-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 1.1" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/7-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 1.1" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/8-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 1.1" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 8.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/7-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/7-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", ">= 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/8-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", ">= 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 8.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/5-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.3.6" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/5-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", [">= 0.4.4", "< 0.6.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/5-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", [">= 0.3.18", "< 0.6.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/5-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", [">= 0.3.18", "< 0.6.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/4-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter", "< 50.0" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 0.15" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 4.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/5-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", [">= 0.18", "< 2.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.0.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/5-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", [">= 0.18", "< 2.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/postgresql/5-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", [">= 0.18", "< 2.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/4-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter", "< 50.0" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.3.6" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 4.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/5-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", ["~> 1.3", ">= 1.3.6"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.1.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/5-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", ["~> 1.3", ">= 1.3.6"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 5.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/4-2.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter", "< 50.0" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", [">= 0.3.13", "< 0.5"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.18.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 4.2.0" 21 | end 22 | 23 | gemspec path: "../../" 24 | -------------------------------------------------------------------------------- /gemfiles/mysql2/6-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", ">= 0.4.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.0.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/mysql2/6-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", "~> 0.5" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.1.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/mysql2/7-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "mysql2", "~> 0.5" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.0.1" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/6-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.0.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/6-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.1.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/7-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcsqlite3-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "sqlite3", "~> 1.4" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.0.1" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/postgresql/6-1.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 1.1" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.1.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/postgresql/7-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", "~> 1.1" 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 7.0.1" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /gemfiles/postgresql/6-0.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcpostgresql-adapter" 10 | end 11 | 12 | platforms :ruby, :mswin, :mingw do 13 | gem "pg", [">= 0.18", "< 2.0"] 14 | end 15 | 16 | gem "rspec", ">= 2.11" 17 | gem "simplecov", ">= 0.20.0", require: false 18 | gem "simplecov-lcov", ">= 0.8.0", require: false 19 | 20 | gem "activerecord", "~> 6.0.0" 21 | 22 | gem "base64" 23 | gem "bigdecimal" 24 | gem "mutex_m" 25 | end 26 | 27 | gemspec path: "../../" 28 | -------------------------------------------------------------------------------- /.github/workflows/publish_gem.yml: -------------------------------------------------------------------------------- 1 | name: Publish Gem 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | 8 | jobs: 9 | push: 10 | if: github.repository == 'collectiveidea/delayed_job_active_record' 11 | runs-on: ubuntu-latest 12 | environment: publishing 13 | 14 | permissions: 15 | contents: write 16 | id-token: write 17 | 18 | steps: 19 | # Set up 20 | - uses: actions/checkout@v4 21 | - name: Set up Ruby 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | bundler-cache: true 25 | ruby-version: ruby 26 | 27 | # Release 28 | - uses: rubygems/release-gem@v1 29 | -------------------------------------------------------------------------------- /lib/generators/delayed_job/upgrade_generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "generators/delayed_job/delayed_job_generator" 4 | require "generators/delayed_job/next_migration_version" 5 | require "rails/generators/migration" 6 | require "rails/generators/active_record" 7 | 8 | # Extend the DelayedJobGenerator so that it creates an AR migration 9 | module DelayedJob 10 | class UpgradeGenerator < ActiveRecordGenerator 11 | def create_migration_file 12 | migration_template( 13 | "upgrade_migration.rb", 14 | "db/migrate/add_queue_to_delayed_jobs.rb", 15 | migration_version: migration_version 16 | ) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/database.yml: -------------------------------------------------------------------------------- 1 | mysql: 2 | adapter: mysql 3 | host: 127.0.0.1 4 | database: delayed_job_test 5 | username: root 6 | port: 3306 7 | encoding: utf8 8 | 9 | mysql2: 10 | adapter: mysql2 11 | host: 127.0.0.1 12 | database: delayed_job_test 13 | username: root 14 | port: 3306 15 | encoding: utf8 16 | 17 | trilogy: 18 | adapter: trilogy 19 | host: 127.0.0.1 20 | database: delayed_job_test 21 | username: root 22 | port: 3306 23 | encoding: utf8 24 | 25 | postgresql: 26 | adapter: postgresql 27 | host: 127.0.0.1 28 | database: delayed_job_test 29 | username: postgres 30 | password: postgres 31 | port: 5432 32 | 33 | sqlite3: 34 | adapter: sqlite3 35 | database: ":memory:" 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute 2 | 3 | If you find what looks like a bug: 4 | 5 | * Search the [mailing list](http://groups.google.com/group/delayed_job) to see if anyone else had the same issue. 6 | * Check the [GitHub issue tracker](http://github.com/collectiveidea/delayed_job_active_record/issues/) to see if anyone else has reported issue. 7 | * If you don't see anything, create an issue with information on how to reproduce it. 8 | 9 | If you want to contribute an enhancement or a fix: 10 | 11 | * Fork the project on github. 12 | * Make your changes with tests. 13 | * Commit the changes without making changes to the Rakefile or any other files that aren't related to your enhancement or fix 14 | * Send a pull request. 15 | -------------------------------------------------------------------------------- /gemfiles/mysql2/master.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbc-adapter", github: "jruby/activerecord-jdbc-adapter" 10 | gem "activerecord-jdbcmysql-adapter", github: "jruby/activerecord-jdbc-adapter" 11 | end 12 | 13 | platforms :ruby, :mswin, :mingw do 14 | gem "mysql2", "~> 0.5" 15 | end 16 | 17 | gem "rspec", ">= 2.11" 18 | gem "simplecov", ">= 0.20.0", require: false 19 | gem "simplecov-lcov", ">= 0.8.0", require: false 20 | 21 | gem "activerecord", github: "rails" 22 | end 23 | 24 | gem "delayed_job", github: "collectiveidea/delayed_job" 25 | 26 | gemspec path: "../../" 27 | -------------------------------------------------------------------------------- /gemfiles/postgresql/master.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbc-adapter", github: "jruby/activerecord-jdbc-adapter" 10 | gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter" 11 | end 12 | 13 | platforms :ruby, :mswin, :mingw do 14 | gem "pg", "~> 1.1" 15 | end 16 | 17 | gem "rspec", ">= 2.11" 18 | gem "simplecov", ">= 0.20.0", require: false 19 | gem "simplecov-lcov", ">= 0.8.0", require: false 20 | 21 | gem "activerecord", github: "rails" 22 | end 23 | 24 | gem "delayed_job", github: "collectiveidea/delayed_job" 25 | 26 | gemspec path: "../../" 27 | -------------------------------------------------------------------------------- /gemfiles/sqlite3/master.gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbc-adapter", github: "jruby/activerecord-jdbc-adapter" 10 | gem "activerecord-jdbcsqlite3-adapter", github: "jruby/activerecord-jdbc-adapter" 11 | end 12 | 13 | platforms :ruby, :mswin, :mingw do 14 | gem "sqlite3", ">= 2.1" 15 | end 16 | 17 | gem "rspec", ">= 2.11" 18 | gem "simplecov", ">= 0.20.0", require: false 19 | gem "simplecov-lcov", ">= 0.8.0", require: false 20 | 21 | gem "activerecord", github: "rails" 22 | end 23 | 24 | gem "delayed_job", github: "collectiveidea/delayed_job" 25 | 26 | gemspec path: "../../" 27 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rake" 6 | 7 | group :test do 8 | platforms :jruby do 9 | gem "activerecord-jdbcmysql-adapter" 10 | gem "activerecord-jdbcpostgresql-adapter" 11 | gem "activerecord-jdbcsqlite3-adapter" 12 | end 13 | 14 | platforms :ruby, :mswin, :mingw do 15 | gem "mysql2", "~> 0.5.0" 16 | gem "pg", "~> 1.1" 17 | gem "sqlite3" 18 | gem "trilogy" 19 | end 20 | 21 | gem "rspec", ">= 3" 22 | 23 | gem "simplecov", ">= 0.20.0", require: false 24 | gem "simplecov-lcov", ">= 0.8.0", require: false 25 | end 26 | 27 | group :rubocop do 28 | gem "rubocop" 29 | gem "rubocop-packaging" 30 | gem "rubocop-performance" 31 | gem "rubocop-rails" 32 | gem "rubocop-rspec" 33 | end 34 | 35 | gemspec 36 | -------------------------------------------------------------------------------- /lib/generators/delayed_job/next_migration_version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module DelayedJob 4 | module NextMigrationVersion 5 | # while methods have moved around this has been the implementation 6 | # since ActiveRecord 3.0 7 | def next_migration_number(dirname) 8 | next_migration_number = current_migration_number(dirname) + 1 9 | timestamped_migrations = 10 | if ActiveRecord.respond_to?(:timestamped_migrations) 11 | ActiveRecord.timestamped_migrations 12 | else 13 | ActiveRecord::Base.timestamped_migrations 14 | end 15 | 16 | if timestamped_migrations 17 | [Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max 18 | else 19 | format("%.3d", next_migration_number) 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_helper" 4 | Bundler::GemHelper.install_tasks 5 | 6 | require "rspec/core/rake_task" 7 | 8 | ADAPTERS = %w[mysql2 trilogy postgresql sqlite3].freeze 9 | 10 | ADAPTERS.each do |adapter| 11 | desc "Run RSpec code examples for #{adapter} adapter" 12 | RSpec::Core::RakeTask.new(adapter => "#{adapter}:adapter") 13 | 14 | namespace adapter do 15 | task :adapter do 16 | ENV["ADAPTER"] = adapter 17 | end 18 | end 19 | end 20 | 21 | task :coverage do 22 | ENV["COVERAGE"] = "true" 23 | end 24 | 25 | task :adapter do 26 | ENV["ADAPTER"] = nil 27 | end 28 | 29 | Rake::Task[:spec].enhance do 30 | require "simplecov" 31 | require "coveralls" 32 | 33 | Coveralls::SimpleCov::Formatter.new.format(SimpleCov.result) 34 | end 35 | 36 | require "rubocop/rake_task" 37 | RuboCop::RakeTask.new 38 | 39 | task default: ([:coverage] + ADAPTERS + [:adapter] + [:rubocop]) 40 | -------------------------------------------------------------------------------- /.github/workflows/rubocop.yml: -------------------------------------------------------------------------------- 1 | name: RuboCop 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | rubocop: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Set up Ruby 3.2 16 | uses: ruby/setup-ruby@v1 17 | with: 18 | ruby-version: 3.2 19 | - name: Generate lockfile for cache key 20 | run: bundle lock 21 | - name: Cache gems 22 | uses: actions/cache@v4 23 | with: 24 | path: vendor/bundle 25 | key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }} 26 | restore-keys: | 27 | ${{ runner.os }}-rubocop- 28 | - name: Install gems 29 | run: | 30 | bundle config path vendor/bundle 31 | bundle config set without 'default test' 32 | bundle install --jobs 4 --retry 3 33 | - name: Run RuboCop 34 | run: bundle exec rubocop --parallel 35 | -------------------------------------------------------------------------------- /delayed_job_active_record.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "delayed_job_active_record" 5 | spec.version = "4.1.11" 6 | spec.summary = "ActiveRecord backend for DelayedJob" 7 | spec.description = "ActiveRecord backend for Delayed::Job, originally authored by Tobias Lütke" 8 | 9 | spec.licenses = "MIT" 10 | 11 | spec.authors = ["David Genord II", "Brian Ryckbost", "Matt Griffin", "Erik Michaels-Ober"] 12 | spec.email = ["david@collectiveidea.com", "bryckbost@gmail.com", "matt@griffinonline.org", "sferik@gmail.com"] 13 | spec.homepage = "http://github.com/collectiveidea/delayed_job_active_record" 14 | 15 | spec.files = %w[CONTRIBUTING.md LICENSE.md README.md delayed_job_active_record.gemspec] + Dir["lib/**/*.rb"] 16 | spec.require_paths = ["lib"] 17 | 18 | spec.metadata = { "rubygems_mfa_required" => "true" } 19 | 20 | spec.add_dependency "activerecord", [">= 3.0", "< 9.0"] 21 | spec.add_dependency "delayed_job", [">= 3.0", "< 5"] 22 | end 23 | -------------------------------------------------------------------------------- /lib/generators/delayed_job/active_record_generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "generators/delayed_job/delayed_job_generator" 4 | require "generators/delayed_job/next_migration_version" 5 | require "rails/generators/migration" 6 | require "rails/generators/active_record" 7 | 8 | # Extend the DelayedJobGenerator so that it creates an AR migration 9 | module DelayedJob 10 | class ActiveRecordGenerator < ::DelayedJobGenerator 11 | include Rails::Generators::Migration 12 | extend NextMigrationVersion 13 | 14 | source_paths << File.join(File.dirname(__FILE__), "templates") 15 | 16 | def create_migration_file 17 | migration_template "migration.rb", "db/migrate/create_delayed_jobs.rb", migration_version: migration_version 18 | end 19 | 20 | def self.next_migration_number(dirname) 21 | ActiveRecord::Generators::Base.next_migration_number dirname 22 | end 23 | 24 | private 25 | 26 | def migration_version 27 | "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" if ActiveRecord::VERSION::MAJOR >= 5 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005 Tobias Lütke 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND 17 | NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/generators/delayed_job/templates/migration.rb: -------------------------------------------------------------------------------- 1 | class CreateDelayedJobs < ActiveRecord::Migration<%= migration_version %> 2 | def self.up 3 | create_table :delayed_jobs do |table| 4 | table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue 5 | table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually. 6 | table.text :handler, null: false # YAML-encoded string of the object that will do work 7 | table.text :last_error # reason for last failure (See Note below) 8 | table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. 9 | table.datetime :locked_at # Set when a client is working on this object 10 | table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) 11 | table.string :locked_by # Who is working on this object (if locked) 12 | table.string :queue # The name of the queue this job is in 13 | table.timestamps null: true 14 | end 15 | 16 | add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority" 17 | end 18 | 19 | def self.down 20 | drop_table :delayed_jobs 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **If you're viewing this at https://github.com/collectiveidea/delayed_job_active_record, 2 | you're reading the documentation for the master branch. 3 | [View documentation for the latest release 4 | (4.1.11).](https://github.com/collectiveidea/delayed_job_active_record/tree/v4.1.11)** 5 | 6 | # DelayedJob ActiveRecord Backend 7 | 8 | [![Gem Version](https://img.shields.io/gem/v/delayed_job_active_record.svg)](https://rubygems.org/gems/delayed_job_active_record) 9 | ![CI](https://github.com/collectiveidea/delayed_job_active_record/workflows/CI/badge.svg) 10 | [![Coverage Status](https://img.shields.io/coveralls/collectiveidea/delayed_job_active_record.svg)](https://coveralls.io/r/collectiveidea/delayed_job_active_record) 11 | 12 | ## Installation 13 | 14 | Add the gem to your Gemfile: 15 | 16 | gem 'delayed_job_active_record' 17 | 18 | Run `bundle install`. 19 | 20 | If you're using Rails, run the generator to create the migration for the 21 | delayed_job table. 22 | 23 | rails g delayed_job:active_record 24 | rake db:migrate 25 | 26 | ## Problems locking jobs 27 | 28 | You can try using the legacy locking code. It is usually slower but works better for certain people. 29 | 30 | Delayed::Backend::ActiveRecord.configuration.reserve_sql_strategy = :default_sql 31 | 32 | ## Upgrading from 2.x to 3.0.0 33 | 34 | If you're upgrading from Delayed Job 2.x, run the upgrade generator to create a 35 | migration to add a column to your delayed_jobs table. 36 | 37 | rails g delayed_job:upgrade 38 | rake db:migrate 39 | 40 | That's it. Use [delayed_job as normal](http://github.com/collectiveidea/delayed_job). 41 | -------------------------------------------------------------------------------- /.github/workflows/canary.yml: -------------------------------------------------------------------------------- 1 | name: Canary 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | name: Test (Ruby ${{ matrix.ruby }}, Gemfile ${{ matrix.gemfile }}) 12 | runs-on: ubuntu-latest 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | ruby: ['3.2', '3.3', 'head', 'jruby-9.4', 'jruby-head'] 17 | gemfile: 18 | - gemfiles/postgresql/master.gemfile 19 | - gemfiles/mysql2/master.gemfile 20 | - gemfiles/sqlite3/master.gemfile 21 | - gemfiles/trilogy/master.gemfile 22 | exclude: 23 | - ruby: 'jruby-9.4' 24 | gemfile: gemfiles/trilogy/master.gemfile 25 | - ruby: 'jruby-head' 26 | gemfile: gemfiles/trilogy/master.gemfile 27 | include: 28 | # jruby with rails 7.1 and 7.2 is still under development with jruby 29 | - ruby: jruby-9.4 30 | gemfile: gemfiles/mysql2/7-1.gemfile 31 | - ruby: jruby-9.4 32 | gemfile: gemfiles/postgresql/7-1.gemfile 33 | - ruby: jruby-9.4 34 | gemfile: gemfiles/sqlite3/7-1.gemfile 35 | - ruby: jruby-9.4 36 | gemfile: gemfiles/mysql2/7-2.gemfile 37 | - ruby: jruby-9.4 38 | gemfile: gemfiles/postgresql/7-2.gemfile 39 | - ruby: jruby-9.4 40 | gemfile: gemfiles/sqlite3/7-2.gemfile 41 | continue-on-error: true 42 | services: 43 | postgres: 44 | image: postgres 45 | # Provide the password for postgres 46 | env: 47 | POSTGRES_DB: delayed_job_test 48 | POSTGRES_PASSWORD: postgres 49 | # Set health checks to wait until postgres has started 50 | options: >- 51 | --health-cmd pg_isready 52 | --health-interval 10s 53 | --health-timeout 5s 54 | --health-retries 5 55 | ports: 56 | # Maps tcp port 5432 on service container to the host 57 | - 5432:5432 58 | mysql: 59 | image: mysql 60 | env: 61 | MYSQL_ALLOW_EMPTY_PASSWORD: yes 62 | MYSQL_DATABASE: delayed_job_test 63 | ports: 64 | - 3306:3306 65 | options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 66 | 67 | steps: 68 | - uses: actions/checkout@v4 69 | - uses: ruby/setup-ruby@v1 70 | env: 71 | BUNDLE_GEMFILE: ${{ matrix.gemfile }} 72 | with: 73 | ruby-version: ${{ matrix.ruby }} 74 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 75 | - name: Run tests 76 | env: 77 | BUNDLE_GEMFILE: ${{ matrix.gemfile }} 78 | run: bundle exec rspec 79 | - name: Coveralls Parallel 80 | uses: coverallsapp/github-action@main 81 | with: 82 | github-token: ${{ secrets.github_token }} 83 | flag-name: run-${{ matrix.ruby }}-${{ matrix.gemfile }} 84 | parallel: true 85 | 86 | finish: 87 | needs: test 88 | runs-on: ubuntu-latest 89 | steps: 90 | - name: Coveralls Finished 91 | uses: coverallsapp/github-action@main 92 | with: 93 | github-token: ${{ secrets.github_token }} 94 | parallel-finished: true 95 | -------------------------------------------------------------------------------- /spec/helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "simplecov" 4 | require "simplecov-lcov" 5 | 6 | SimpleCov::Formatter::LcovFormatter.config do |c| 7 | c.report_with_single_file = true 8 | c.single_report_path = "coverage/lcov.info" 9 | end 10 | SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new( 11 | [ 12 | SimpleCov::Formatter::HTMLFormatter, 13 | SimpleCov::Formatter::LcovFormatter 14 | ] 15 | ) 16 | 17 | SimpleCov.start do 18 | add_filter "/spec/" 19 | end 20 | 21 | require "logger" 22 | require "rspec" 23 | 24 | begin 25 | require "protected_attributes" 26 | rescue LoadError # rubocop:disable Lint/SuppressedException 27 | end 28 | require "delayed_job_active_record" 29 | require "delayed/backend/shared_spec" 30 | 31 | Delayed::Worker.logger = Logger.new("/tmp/dj.log") 32 | ENV["RAILS_ENV"] = "test" 33 | 34 | db_adapter = ENV.fetch("ADAPTER", nil) 35 | gemfile = ENV.fetch("BUNDLE_GEMFILE", nil) 36 | db_adapter ||= gemfile && gemfile[%r{gemfiles/(.*?)/}] && $1 # rubocop:disable Style/PerlBackrefs 37 | db_adapter ||= "sqlite3" 38 | 39 | if db_adapter == "trilogy" && Gem::Version.new("7.1") > Gem::Version.new(ActiveRecord::VERSION::STRING) 40 | require "trilogy_adapter/connection" 41 | ActiveSupport.on_load(:active_record) { extend TrilogyAdapter::Connection } 42 | end 43 | 44 | config = YAML.load_file("spec/database.yml") 45 | ActiveRecord::Base.establish_connection config[db_adapter] 46 | ActiveRecord::Base.logger = Delayed::Worker.logger 47 | ActiveRecord::Migration.verbose = false 48 | 49 | # MySQL 5.7 no longer supports null default values for the primary key 50 | # Override the default primary key type in Rails <= 4.0 51 | # https://stackoverflow.com/a/34555109 52 | if db_adapter == "mysql2" 53 | types = if defined?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter) 54 | # ActiveRecord 3.2+ 55 | ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::NATIVE_DATABASE_TYPES 56 | else 57 | # ActiveRecord < 3.2 58 | ActiveRecord::ConnectionAdapters::Mysql2Adapter::NATIVE_DATABASE_TYPES 59 | end 60 | types[:primary_key] = types[:primary_key].sub(" DEFAULT NULL", "") 61 | end 62 | 63 | migration_template = File.open("lib/generators/delayed_job/templates/migration.rb") 64 | 65 | # need to eval the template with the migration_version intact 66 | migration_context = 67 | Class.new do 68 | def my_binding 69 | binding 70 | end 71 | 72 | private 73 | 74 | def migration_version 75 | "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" if ActiveRecord::VERSION::MAJOR >= 5 76 | end 77 | end 78 | 79 | migration_ruby = ERB.new(migration_template.read).result(migration_context.new.my_binding) 80 | eval(migration_ruby) # rubocop:disable Security/Eval 81 | 82 | ActiveRecord::Schema.define do 83 | if table_exists?(:delayed_jobs) 84 | # `if_exists: true` was only added in Rails 5 85 | drop_table :delayed_jobs 86 | end 87 | 88 | CreateDelayedJobs.up 89 | 90 | create_table :stories, primary_key: :story_id, force: true do |table| 91 | table.string :text 92 | table.boolean :scoped, default: true 93 | end 94 | end 95 | 96 | # Purely useful for test cases... 97 | class Story < ActiveRecord::Base 98 | if ::ActiveRecord::VERSION::MAJOR < 4 && ActiveRecord::VERSION::MINOR < 2 99 | set_primary_key :story_id 100 | else 101 | self.primary_key = :story_id 102 | end 103 | def tell 104 | text 105 | end 106 | 107 | def whatever(number) 108 | tell * number 109 | end 110 | default_scope { where(scoped: true) } 111 | 112 | handle_asynchronously :whatever 113 | end 114 | 115 | # Add this directory so the ActiveSupport autoloading works 116 | ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__) 117 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - rubocop-packaging 3 | - rubocop-performance 4 | - rubocop-rails 5 | - rubocop-rspec 6 | 7 | Rails: 8 | Enabled: true 9 | AllCops: 10 | Exclude: 11 | - lib/**/templates/* 12 | - vendor/**/* 13 | NewCops: enable 14 | SuggestExtensions: false 15 | TargetRubyVersion: 2.0 16 | 17 | ################# 18 | # [i] Overrides # 19 | ################# 20 | 21 | Style/CollectionMethods: 22 | Enabled: true 23 | # Mapping from undesired method to desired_method 24 | # e.g. to use `detect` over `find`: 25 | # 26 | # CollectionMethods: 27 | # PreferredMethods: 28 | # find: detect 29 | PreferredMethods: 30 | reduce: 'inject' 31 | find: 'detect' 32 | each_with_index: 'each.with_index' 33 | 34 | Style/EmptyMethod: 35 | EnforcedStyle: expanded 36 | 37 | # Align ends correctly. 38 | Layout/EndAlignment: 39 | EnforcedStyleAlignWith: variable 40 | 41 | Layout/LineLength: 42 | Max: 120 43 | 44 | Style/SignalException: 45 | EnforcedStyle: only_raise 46 | 47 | Layout/SpaceInsideBlockBraces: 48 | SpaceBeforeBlockParameters: true 49 | 50 | Layout/SpaceInsideHashLiteralBraces: 51 | EnforcedStyle: space 52 | 53 | Style/StringLiterals: 54 | EnforcedStyle: double_quotes 55 | 56 | ################# 57 | # Disabled cops # 58 | ################# 59 | # We actually still work with ruby 2.0 but this setting only supports 2.4+ 60 | # We aren't going to drop old versions just to make rubocop happy. 61 | Gemspec/RequiredRubyVersion: 62 | Enabled: false 63 | 64 | Metrics/ClassLength: 65 | Enabled: false 66 | 67 | Metrics/CyclomaticComplexity: 68 | Enabled: false 69 | 70 | Metrics/MethodLength: 71 | Enabled: false 72 | 73 | Style/ClassAndModuleChildren: 74 | Enabled: false 75 | 76 | Style/Documentation: 77 | Enabled: false 78 | 79 | Style/EachWithObject: 80 | Enabled: false 81 | 82 | Style/FormatString: 83 | Enabled: false 84 | 85 | Style/Lambda: 86 | Enabled: false 87 | 88 | Style/MultipleComparison: 89 | Enabled: false 90 | 91 | Style/NegatedIf: 92 | Enabled: false 93 | 94 | Style/PercentLiteralDelimiters: 95 | PreferredDelimiters: 96 | "%w": "[]" 97 | "%W": "[]" 98 | "%i": "[]" 99 | "%I": "[]" 100 | 101 | Style/Semicolon: 102 | Enabled: false 103 | 104 | Style/SingleLineBlockParams: 105 | Enabled: false 106 | 107 | Style/WordArray: 108 | Enabled: false 109 | 110 | # HABTM still has a place. 111 | # http://collectiveidea.com/blog/archives/2014/08/11/has_and_belongs_to_many-isnt-dead/ 112 | Rails/HasAndBelongsToMany: 113 | Enabled: false 114 | 115 | Rails/RakeEnvironment: 116 | Enabled: false 117 | 118 | # enforces using the class name in a describe block (e.g. `describe TestedClass do`) 119 | RSpec/DescribeClass: 120 | Enabled: false 121 | 122 | # enforces using the described_class variablea (`described_class` instead of MyClass) 123 | RSpec/DescribedClass: 124 | Enabled: false 125 | 126 | # RSpec examples are ok if they're long. 127 | # Explicitness is better than cleverness in tests. 128 | RSpec/ExampleLength: 129 | Enabled: false 130 | 131 | # enforces using either `expect` or `allow` for stubs. Since they do different things, 132 | # we should let the developer decide which to use 133 | RSpec/MessageExpectation: 134 | Enabled: false 135 | 136 | # enforces having only one `expect` per test 137 | RSpec/MultipleExpectations: 138 | Enabled: false 139 | 140 | RSpec/MultipleMemoizedHelpers: 141 | Enabled: false 142 | 143 | # enforces rules about how many nested `describe` blocks are allowed 144 | RSpec/NestedGroups: 145 | Enabled: false 146 | 147 | # enforces rules about using `it` or `describe` block methods instead of `feature` or `scenario` 148 | RSpec/Dialect: 149 | Enabled: false 150 | 151 | RSpec/SpecFilePathFormat: 152 | Enabled: false 153 | 154 | ################### 155 | # Local overrides # 156 | ################### 157 | 158 | Rails/ApplicationRecord: 159 | Enabled: false 160 | 161 | Rails/SkipsModelValidations: 162 | Enabled: false 163 | 164 | Security/YAMLLoad: 165 | Enabled: false 166 | 167 | Style/FormatStringToken: 168 | Enabled: false 169 | 170 | Style/NumericPredicate: 171 | Enabled: false 172 | -------------------------------------------------------------------------------- /spec/delayed/backend/active_record_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "helper" 4 | require "delayed/backend/active_record" 5 | 6 | describe Delayed::Backend::ActiveRecord::Job do 7 | it_behaves_like "a delayed_job backend" 8 | 9 | describe "configuration" do 10 | describe "reserve_sql_strategy" do 11 | let(:configuration) { Delayed::Backend::ActiveRecord.configuration } 12 | 13 | it "allows :optimized_sql" do 14 | configuration.reserve_sql_strategy = :optimized_sql 15 | expect(configuration.reserve_sql_strategy).to eq(:optimized_sql) 16 | end 17 | 18 | it "allows :default_sql" do 19 | configuration.reserve_sql_strategy = :default_sql 20 | expect(configuration.reserve_sql_strategy).to eq(:default_sql) 21 | end 22 | 23 | it "raises an argument error on invalid entry" do 24 | expect { configuration.reserve_sql_strategy = :invalid }.to raise_error(ArgumentError) 25 | end 26 | end 27 | end 28 | 29 | describe "reserve_with_scope" do 30 | let(:relation_class) { Delayed::Job.limit(1).class } 31 | let(:worker) { instance_double(Delayed::Worker, name: "worker01", read_ahead: 1) } 32 | let(:limit) { instance_double(relation_class, update_all: 0) } 33 | let(:where) { instance_double(relation_class, update_all: 0) } 34 | let(:scope) { instance_double(relation_class, limit: limit, where: where) } 35 | let(:job) { instance_double(Delayed::Job, id: 1) } 36 | 37 | before do 38 | allow(Delayed::Backend::ActiveRecord::Job.connection).to receive(:adapter_name).at_least(:once).and_return(dbms) 39 | Delayed::Backend::ActiveRecord.configuration.reserve_sql_strategy = reserve_sql_strategy 40 | end 41 | 42 | context "with reserve_sql_strategy option set to :optimized_sql (default)" do 43 | let(:reserve_sql_strategy) { :optimized_sql } 44 | 45 | context "for mysql adapters" do 46 | let(:dbms) { "MySQL" } 47 | 48 | it "uses the optimized sql version" do 49 | allow(Delayed::Backend::ActiveRecord::Job).to receive(:reserve_with_scope_using_default_sql) 50 | Delayed::Backend::ActiveRecord::Job.reserve_with_scope(scope, worker, Time.current) 51 | expect(Delayed::Backend::ActiveRecord::Job).not_to have_received(:reserve_with_scope_using_default_sql) 52 | end 53 | end 54 | 55 | context "for a dbms without a specific implementation" do 56 | let(:dbms) { "OtherDB" } 57 | 58 | it "uses the plain sql version" do 59 | allow(Delayed::Backend::ActiveRecord::Job).to receive(:reserve_with_scope_using_default_sql) 60 | Delayed::Backend::ActiveRecord::Job.reserve_with_scope(scope, worker, Time.current) 61 | expect(Delayed::Backend::ActiveRecord::Job).to have_received(:reserve_with_scope_using_default_sql).once 62 | end 63 | end 64 | end 65 | 66 | context "with reserve_sql_strategy option set to :default_sql" do 67 | let(:dbms) { "MySQL" } 68 | let(:reserve_sql_strategy) { :default_sql } 69 | 70 | it "uses the plain sql version" do 71 | allow(Delayed::Backend::ActiveRecord::Job).to receive(:reserve_with_scope_using_default_sql) 72 | Delayed::Backend::ActiveRecord::Job.reserve_with_scope(scope, worker, Time.current) 73 | expect(Delayed::Backend::ActiveRecord::Job).to have_received(:reserve_with_scope_using_default_sql).once 74 | end 75 | end 76 | end 77 | 78 | context "db_time_now" do 79 | def use_default_timezone(timezone) 80 | if ActiveRecord.respond_to?(:default_timezone=) 81 | ActiveRecord.default_timezone = timezone 82 | else 83 | ActiveRecord::Base.default_timezone = timezone 84 | end 85 | end 86 | 87 | after do 88 | Time.zone = nil 89 | use_default_timezone(:local) 90 | end 91 | 92 | it "returns time in current time zone if set" do 93 | Time.zone = "Arizona" 94 | expect(Delayed::Job.db_time_now.zone).to eq("MST") 95 | end 96 | 97 | it "returns UTC time if that is the AR default" do 98 | Time.zone = nil 99 | use_default_timezone(:utc) 100 | expect(Delayed::Backend::ActiveRecord::Job.db_time_now.zone).to eq "UTC" 101 | end 102 | 103 | it "returns local time if that is the AR default" do 104 | Time.zone = "Arizona" 105 | use_default_timezone(:local) 106 | expect(Delayed::Backend::ActiveRecord::Job.db_time_now.zone).to eq("MST") 107 | end 108 | end 109 | 110 | describe "before_fork" do 111 | it "clears all connections connection" do 112 | allow(ActiveRecord::Base.connection_handler).to receive(:clear_all_connections!) 113 | Delayed::Backend::ActiveRecord::Job.before_fork 114 | 115 | if Gem::Version.new("7.1.0") <= Gem::Version.new(ActiveRecord::VERSION::STRING) 116 | expect(ActiveRecord::Base.connection_handler).to have_received(:clear_all_connections!).with(:all) 117 | else 118 | expect(ActiveRecord::Base.connection_handler).to have_received(:clear_all_connections!) 119 | end 120 | end 121 | end 122 | 123 | describe "after_fork" do 124 | it "calls reconnect on the connection" do 125 | allow(ActiveRecord::Base).to receive(:establish_connection) 126 | Delayed::Backend::ActiveRecord::Job.after_fork 127 | expect(ActiveRecord::Base).to have_received(:establish_connection) 128 | end 129 | end 130 | 131 | describe "enqueue" do 132 | it "allows enqueue hook to modify job at DB level" do 133 | later = described_class.db_time_now + 20.minutes 134 | job = Delayed::Backend::ActiveRecord::Job.enqueue payload_object: EnqueueJobMod.new 135 | expect(Delayed::Backend::ActiveRecord::Job.find(job.id).run_at).to be_within(1).of(later) 136 | end 137 | end 138 | 139 | if ActiveRecord::VERSION::MAJOR < 4 || defined?(ActiveRecord::MassAssignmentSecurity) 140 | context "ActiveRecord::Base.send(:attr_accessible, nil)" do 141 | before do 142 | Delayed::Backend::ActiveRecord::Job.send(:attr_accessible, nil) 143 | end 144 | 145 | after do 146 | Delayed::Backend::ActiveRecord::Job.send( 147 | :attr_accessible, 148 | *Delayed::Backend::ActiveRecord::Job.new.attributes.keys 149 | ) 150 | end 151 | 152 | it "is still accessible" do 153 | job = Delayed::Backend::ActiveRecord::Job.enqueue payload_object: EnqueueJobMod.new 154 | expect(Delayed::Backend::ActiveRecord::Job.find(job.id).handler).not_to be_blank 155 | end 156 | end 157 | end 158 | 159 | context "ActiveRecord::Base.table_name_prefix" do 160 | it "when prefix is not set, use 'delayed_jobs' as table name" do 161 | ActiveRecord::Base.table_name_prefix = nil 162 | Delayed::Backend::ActiveRecord::Job.set_delayed_job_table_name 163 | 164 | expect(Delayed::Backend::ActiveRecord::Job.table_name).to eq "delayed_jobs" 165 | end 166 | 167 | it "when prefix is set, prepend it before default table name" do 168 | ActiveRecord::Base.table_name_prefix = "custom_" 169 | Delayed::Backend::ActiveRecord::Job.set_delayed_job_table_name 170 | 171 | expect(Delayed::Backend::ActiveRecord::Job.table_name).to eq "custom_delayed_jobs" 172 | 173 | ActiveRecord::Base.table_name_prefix = nil 174 | Delayed::Backend::ActiveRecord::Job.set_delayed_job_table_name 175 | end 176 | end 177 | end 178 | -------------------------------------------------------------------------------- /lib/delayed/backend/active_record.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "active_record/version" 4 | module Delayed 5 | module Backend 6 | module ActiveRecord 7 | class Configuration 8 | attr_reader :reserve_sql_strategy 9 | 10 | def initialize 11 | self.reserve_sql_strategy = :optimized_sql 12 | end 13 | 14 | def reserve_sql_strategy=(val) 15 | if !(val == :optimized_sql || val == :default_sql) 16 | raise ArgumentError, "allowed values are :optimized_sql or :default_sql" 17 | end 18 | 19 | @reserve_sql_strategy = val 20 | end 21 | end 22 | 23 | def self.configuration 24 | @configuration ||= Configuration.new 25 | end 26 | 27 | def self.configure 28 | yield(configuration) 29 | end 30 | 31 | # A job object that is persisted to the database. 32 | # Contains the work object as a YAML field. 33 | class Job < ::ActiveRecord::Base 34 | include Delayed::Backend::Base 35 | 36 | if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity) 37 | attr_accessible :priority, :run_at, :queue, :payload_object, 38 | :failed_at, :locked_at, :locked_by, :handler 39 | end 40 | 41 | scope :by_priority, lambda { order("priority ASC, run_at ASC") } 42 | scope :min_priority, lambda { where("priority >= ?", Worker.min_priority) if Worker.min_priority } 43 | scope :max_priority, lambda { where("priority <= ?", Worker.max_priority) if Worker.max_priority } 44 | scope :for_queues, lambda { |queues = Worker.queues| where(queue: queues) if Array(queues).any? } 45 | 46 | before_save :set_default_run_at 47 | 48 | def self.set_delayed_job_table_name 49 | delayed_job_table_name = "#{::ActiveRecord::Base.table_name_prefix}delayed_jobs" 50 | self.table_name = delayed_job_table_name 51 | end 52 | 53 | set_delayed_job_table_name 54 | 55 | def self.ready_to_run(worker_name, max_run_time) 56 | where( 57 | "((run_at <= ? AND (locked_at IS NULL OR locked_at < ?)) OR locked_by = ?) AND failed_at IS NULL", 58 | db_time_now, 59 | db_time_now - max_run_time, 60 | worker_name 61 | ) 62 | end 63 | 64 | def self.before_fork 65 | if Gem::Version.new("7.1.0") <= Gem::Version.new(::ActiveRecord::VERSION::STRING) 66 | ::ActiveRecord::Base.connection_handler.clear_all_connections!(:all) 67 | else 68 | ::ActiveRecord::Base.connection_handler.clear_all_connections! 69 | end 70 | end 71 | 72 | def self.after_fork 73 | ::ActiveRecord::Base.establish_connection 74 | end 75 | 76 | # When a worker is exiting, make sure we don't have any locked jobs. 77 | def self.clear_locks!(worker_name) 78 | where(locked_by: worker_name).update_all(locked_by: nil, locked_at: nil) 79 | end 80 | 81 | def self.reserve(worker, max_run_time = Worker.max_run_time) 82 | ready_scope = 83 | ready_to_run(worker.name, max_run_time) 84 | .min_priority 85 | .max_priority 86 | .for_queues 87 | .by_priority 88 | 89 | reserve_with_scope(ready_scope, worker, db_time_now) 90 | end 91 | 92 | def self.reserve_with_scope(ready_scope, worker, now) 93 | case Delayed::Backend::ActiveRecord.configuration.reserve_sql_strategy 94 | # Optimizations for faster lookups on some common databases 95 | when :optimized_sql 96 | reserve_with_scope_using_optimized_sql(ready_scope, worker, now) 97 | # Slower but in some cases more unproblematic strategy to lookup records 98 | # See https://github.com/collectiveidea/delayed_job_active_record/pull/89 for more details. 99 | when :default_sql 100 | reserve_with_scope_using_default_sql(ready_scope, worker, now) 101 | end 102 | end 103 | 104 | def self.reserve_with_scope_using_optimized_sql(ready_scope, worker, now) 105 | case connection.adapter_name 106 | when "PostgreSQL", "PostGIS" 107 | reserve_with_scope_using_optimized_postgres(ready_scope, worker, now) 108 | when "MySQL", "Mysql2", "Trilogy" 109 | reserve_with_scope_using_optimized_mysql(ready_scope, worker, now) 110 | when "MSSQL", "Teradata" 111 | reserve_with_scope_using_optimized_mssql(ready_scope, worker, now) 112 | # Fallback for unknown / other DBMS 113 | else 114 | reserve_with_scope_using_default_sql(ready_scope, worker, now) 115 | end 116 | end 117 | 118 | def self.reserve_with_scope_using_default_sql(ready_scope, worker, now) 119 | # This is our old fashion, tried and true, but possibly slower lookup 120 | # Instead of reading the entire job record for our detect loop, we select only the id, 121 | # and only read the full job record after we've successfully locked the job. 122 | # This can have a noticeable impact on large read_ahead configurations and large payload jobs. 123 | ready_scope.limit(worker.read_ahead).select(:id).detect do |job| 124 | count = ready_scope.where(id: job.id).update_all(locked_at: now, locked_by: worker.name) 125 | count == 1 && job.reload 126 | end 127 | end 128 | 129 | def self.reserve_with_scope_using_optimized_postgres(ready_scope, worker, now) 130 | # Custom SQL required for PostgreSQL because postgres does not support UPDATE...LIMIT 131 | # This locks the single record 'FOR UPDATE' in the subquery 132 | # http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE 133 | # Note: active_record would attempt to generate UPDATE...LIMIT like 134 | # SQL for Postgres if we use a .limit() filter, but it would not 135 | # use 'FOR UPDATE' and we would have many locking conflicts 136 | subquery = ready_scope.limit(1).lock(true).select("id").to_sql 137 | 138 | # On PostgreSQL >= 9.5 we leverage SKIP LOCK to avoid multiple workers blocking each other 139 | # when attempting to get the next available job 140 | # https://www.postgresql.org/docs/9.5/sql-select.html#SQL-FOR-UPDATE-SHARE 141 | if connection.send(:postgresql_version) >= 9_05_00 # rubocop:disable Style/NumericLiterals 142 | subquery += " SKIP LOCKED" 143 | end 144 | 145 | quoted_name = connection.quote_table_name(table_name) 146 | find_by_sql( 147 | [ 148 | "UPDATE #{quoted_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery}) RETURNING *", 149 | now, 150 | worker.name 151 | ] 152 | ).first 153 | end 154 | 155 | def self.reserve_with_scope_using_optimized_mysql(ready_scope, worker, now) 156 | # Removing the millisecond precision from now(time object) 157 | # MySQL 5.6.4 onwards millisecond precision exists, but the 158 | # datetime object created doesn't have precision, so discarded 159 | # while updating. But during the where clause, for mysql(>=5.6.4), 160 | # it queries with precision as well. So removing the precision 161 | now = now.change(usec: 0) 162 | # This works on MySQL and possibly some other DBs that support 163 | # UPDATE...LIMIT. It uses separate queries to lock and return the job 164 | count = ready_scope.limit(1).update_all(locked_at: now, locked_by: worker.name) 165 | return nil if count == 0 166 | 167 | where(locked_at: now, locked_by: worker.name, failed_at: nil).first 168 | end 169 | 170 | def self.reserve_with_scope_using_optimized_mssql(ready_scope, worker, now) 171 | # The MSSQL driver doesn't generate a limit clause when update_all 172 | # is called directly 173 | subsubquery_sql = ready_scope.limit(1).to_sql 174 | # select("id") doesn't generate a subquery, so force a subquery 175 | subquery_sql = "SELECT id FROM (#{subsubquery_sql}) AS x" 176 | quoted_table_name = connection.quote_table_name(table_name) 177 | sql = "UPDATE #{quoted_table_name} SET locked_at = ?, locked_by = ? WHERE id IN (#{subquery_sql})" 178 | count = connection.execute(sanitize_sql([sql, now, worker.name])) 179 | return nil if count == 0 180 | 181 | # MSSQL JDBC doesn't support OUTPUT INSERTED.* for returning a result set, so query locked row 182 | where(locked_at: now, locked_by: worker.name, failed_at: nil).first 183 | end 184 | 185 | # Get the current time (GMT or local depending on DB) 186 | # Note: This does not ping the DB to get the time, so all your clients 187 | # must have synchronized clocks. 188 | def self.db_time_now 189 | if Time.zone 190 | Time.zone.now 191 | elsif default_timezone == :utc 192 | Time.now.utc 193 | else 194 | Time.now # rubocop:disable Rails/TimeZone 195 | end 196 | end 197 | 198 | def self.default_timezone 199 | if ::ActiveRecord.respond_to?(:default_timezone) 200 | ::ActiveRecord.default_timezone 201 | else 202 | ::ActiveRecord::Base.default_timezone 203 | end 204 | end 205 | 206 | def reload(*args) 207 | reset 208 | super 209 | end 210 | end 211 | end 212 | end 213 | end 214 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | name: Test (Ruby ${{ matrix.ruby }}, Gemfile ${{ matrix.gemfile }}) 12 | runs-on: ubuntu-${{ matrix.ubuntu }} 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | ruby: ['3.2', '3.3'] 17 | gemfile: 18 | - gemfiles/mysql2/7-1.gemfile 19 | - gemfiles/postgresql/7-1.gemfile 20 | - gemfiles/sqlite3/7-1.gemfile 21 | - gemfiles/trilogy/7-1.gemfile 22 | - gemfiles/mysql2/7-2.gemfile 23 | - gemfiles/postgresql/7-2.gemfile 24 | - gemfiles/sqlite3/7-2.gemfile 25 | - gemfiles/trilogy/7-2.gemfile 26 | - gemfiles/mysql2/8-0.gemfile 27 | - gemfiles/postgresql/8-0.gemfile 28 | - gemfiles/sqlite3/8-0.gemfile 29 | - gemfiles/trilogy/8-0.gemfile 30 | ubuntu: ['latest'] 31 | include: 32 | # 33 | # Current older ruby 34 | # 35 | - ruby: '2.7' 36 | gemfile: gemfiles/mysql2/7-1.gemfile 37 | ubuntu: latest 38 | - ruby: '2.7' 39 | gemfile: gemfiles/postgresql/7-1.gemfile 40 | ubuntu: latest 41 | - ruby: '2.7' 42 | gemfile: gemfiles/sqlite3/7-1.gemfile 43 | ubuntu: latest 44 | - ruby: '2.7' 45 | gemfile: gemfiles/trilogy/7-1.gemfile 46 | ubuntu: latest 47 | - ruby: '3.0' 48 | gemfile: gemfiles/mysql2/7-1.gemfile 49 | ubuntu: latest 50 | - ruby: '3.0' 51 | gemfile: gemfiles/postgresql/7-1.gemfile 52 | ubuntu: latest 53 | - ruby: '3.0' 54 | gemfile: gemfiles/sqlite3/7-1.gemfile 55 | ubuntu: latest 56 | - ruby: '3.0' 57 | gemfile: gemfiles/trilogy/7-1.gemfile 58 | ubuntu: latest 59 | - ruby: '3.1' 60 | gemfile: gemfiles/mysql2/7-1.gemfile 61 | ubuntu: latest 62 | - ruby: '3.1' 63 | gemfile: gemfiles/postgresql/7-1.gemfile 64 | ubuntu: latest 65 | - ruby: '3.1' 66 | gemfile: gemfiles/sqlite3/7-1.gemfile 67 | ubuntu: latest 68 | - ruby: '3.1' 69 | gemfile: gemfiles/trilogy/7-1.gemfile 70 | ubuntu: latest 71 | - ruby: '3.1' 72 | gemfile: gemfiles/mysql2/7-2.gemfile 73 | ubuntu: latest 74 | - ruby: '3.1' 75 | gemfile: gemfiles/postgresql/7-2.gemfile 76 | ubuntu: latest 77 | - ruby: '3.1' 78 | gemfile: gemfiles/sqlite3/7-2.gemfile 79 | ubuntu: latest 80 | - ruby: '3.1' 81 | gemfile: gemfiles/trilogy/7-2.gemfile 82 | ubuntu: latest 83 | 84 | 85 | # 86 | # The past 87 | # 88 | # EOL Active Record 89 | # Rails 3.2 was maintained longer and is ruby 2.2 compatible 90 | - ruby: '2.2' 91 | gemfile: gemfiles/postgresql/3-2.gemfile 92 | ubuntu: '20.04' 93 | - ruby: '2.2' 94 | gemfile: gemfiles/sqlite3/3-2.gemfile 95 | ubuntu: '20.04' 96 | # Rails <= 4.0 was only compatible with ruby 2.0 97 | # The test were running, but there are known incompatibilites 98 | - ruby: 2.0.0 99 | gemfile: gemfiles/postgresql/3-0.gemfile 100 | ubuntu: '20.04' 101 | - ruby: 2.0.0 102 | gemfile: gemfiles/sqlite3/3-0.gemfile 103 | ubuntu: '20.04' 104 | - ruby: 2.0.0 105 | gemfile: gemfiles/postgresql/3-1.gemfile 106 | ubuntu: '20.04' 107 | - ruby: 2.0.0 108 | gemfile: gemfiles/sqlite3/3-1.gemfile 109 | ubuntu: '20.04' 110 | - ruby: 2.0.0 111 | gemfile: gemfiles/postgresql/4-0.gemfile 112 | ubuntu: '20.04' 113 | - ruby: 2.0.0 114 | gemfile: gemfiles/sqlite3/4-0.gemfile 115 | ubuntu: '20.04' 116 | # Rails 4.1 was only compatible with ruby 2.1 117 | - ruby: '2.1' 118 | gemfile: gemfiles/postgresql/4-1.gemfile 119 | ubuntu: '20.04' 120 | - ruby: '2.1' 121 | gemfile: gemfiles/sqlite3/4-1.gemfile 122 | ubuntu: '20.04' 123 | # Rails 4.2 was EOL with the release of 6.0 and compatible with ruby 2.4 124 | - ruby: '2.4' 125 | gemfile: gemfiles/mysql2/4-2.gemfile 126 | ubuntu: '20.04' 127 | - ruby: '2.4' 128 | gemfile: gemfiles/postgresql/4-2.gemfile 129 | ubuntu: '20.04' 130 | - ruby: '2.4' 131 | gemfile: gemfiles/sqlite3/4-2.gemfile 132 | ubuntu: '20.04' 133 | # Rails 5.0 was EOL with the release of 5.2 and compatible with ruby 2.4 134 | - ruby: '2.4' 135 | gemfile: gemfiles/mysql2/5-0.gemfile 136 | ubuntu: '20.04' 137 | - ruby: '2.4' 138 | gemfile: gemfiles/postgresql/5-0.gemfile 139 | ubuntu: '20.04' 140 | - ruby: '2.4' 141 | gemfile: gemfiles/sqlite3/5-0.gemfile 142 | ubuntu: '20.04' 143 | # Rails 5.1 was EOL with the release of 6.0 and compatible with ruby 2.5 144 | - ruby: '2.5' 145 | gemfile: gemfiles/mysql2/5-1.gemfile 146 | ubuntu: '20.04' 147 | - ruby: '2.5' 148 | gemfile: gemfiles/postgresql/5-1.gemfile 149 | ubuntu: '20.04' 150 | - ruby: '2.5' 151 | gemfile: gemfiles/sqlite3/5-1.gemfile 152 | ubuntu: '20.04' 153 | # Rails 6.0 was EOL with the release of 7.2 and compatible with ruby 3.3 154 | - ruby: '3.3' 155 | gemfile: gemfiles/mysql2/6-0.gemfile 156 | ubuntu: '22.04' 157 | - ruby: '3.3' 158 | gemfile: gemfiles/trilogy/6-0.gemfile 159 | ubuntu: '22.04' 160 | - ruby: '3.3' 161 | gemfile: gemfiles/postgresql/6-0.gemfile 162 | ubuntu: '22.04' 163 | - ruby: '3.3' 164 | gemfile: gemfiles/sqlite3/6-0.gemfile 165 | ubuntu: '22.04' 166 | # Rails 6.1 was EOL with the release of 7.2 and compatible with ruby 3.3 167 | - ruby: '3.3' 168 | gemfile: gemfiles/mysql2/6-1.gemfile 169 | ubuntu: '22.04' 170 | - ruby: '3.3' 171 | gemfile: gemfiles/trilogy/6-1.gemfile 172 | ubuntu: '22.04' 173 | - ruby: '3.3' 174 | gemfile: gemfiles/postgresql/6-1.gemfile 175 | ubuntu: '22.04' 176 | - ruby: '3.3' 177 | gemfile: gemfiles/sqlite3/6-1.gemfile 178 | ubuntu: '22.04' 179 | # Rails 7.0 was EOL with the release of 7.2 and compatible with ruby 3.3 180 | - ruby: '3.3' 181 | gemfile: gemfiles/mysql2/7-0.gemfile 182 | ubuntu: '22.04' 183 | - ruby: '3.3' 184 | gemfile: gemfiles/trilogy/7-0.gemfile 185 | ubuntu: '22.04' 186 | - ruby: '3.3' 187 | gemfile: gemfiles/postgresql/7-0.gemfile 188 | ubuntu: '22.04' 189 | - ruby: '3.3' 190 | gemfile: gemfiles/sqlite3/7-0.gemfile 191 | ubuntu: '22.04' 192 | 193 | # 194 | # The parallel dimension 195 | # 196 | # Rubinius (Isn't supported on Github Actions) 197 | # - rvm: rbx-2 198 | # gemfile: gemfiles/mysql2/6-0.gemfile 199 | # - rvm: rbx-2 200 | # gemfile: gemfiles/postgresql/6-0.gemfile 201 | # - rvm: rbx-2 202 | # gemfile: gemfiles/sqlite3/6-0.gemfile 203 | exclude: 204 | # jruby doesn't support trilogy 205 | - ruby: 'jruby-9.4' 206 | gemfile: gemfiles/trilogy/7-1.gemfile 207 | - ruby: 'jruby-9.4' 208 | gemfile: gemfiles/trilogy/7-2.gemfile 209 | services: 210 | postgres: 211 | # AR before 4.2.6 doesn't work with 12 212 | image: postgres:11-alpine 213 | # Provide the password for postgres 214 | env: 215 | POSTGRES_DB: delayed_job_test 216 | POSTGRES_PASSWORD: postgres 217 | # Set health checks to wait until postgres has started 218 | options: >- 219 | --health-cmd pg_isready 220 | --health-interval 10s 221 | --health-timeout 5s 222 | --health-retries 5 223 | ports: 224 | # Maps tcp port 5432 on service container to the host 225 | - 5432:5432 226 | mysql: 227 | image: mysql:5.7 228 | env: 229 | MYSQL_ALLOW_EMPTY_PASSWORD: yes 230 | MYSQL_DATABASE: delayed_job_test 231 | ports: 232 | - 3306:3306 233 | options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 234 | 235 | steps: 236 | - uses: actions/checkout@v4 237 | - name: Reinstall libpg 238 | if: ${{ matrix.ruby < '2.4' && contains(matrix.gemfile, 'postgresql') }} 239 | # version located via https://pkgs.org/search/?q=libpq5 and the Ubuntu 20.04 LTS package list 240 | run: sudo apt-get update && sudo apt-get install -y --allow-downgrades libpq5=12.19-0ubuntu0.20.04.1 && sudo apt-get install -y --allow-downgrades libpq-dev 241 | - uses: ruby/setup-ruby@v1 242 | env: 243 | BUNDLE_GEMFILE: ${{ matrix.gemfile }} 244 | with: 245 | ruby-version: ${{ matrix.ruby }} 246 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 247 | cache-version: 2 248 | - name: Run tests 249 | env: 250 | BUNDLE_GEMFILE: ${{ matrix.gemfile }} 251 | run: bundle exec rspec 252 | - name: Coveralls Parallel 253 | uses: coverallsapp/github-action@main 254 | with: 255 | github-token: ${{ secrets.github_token }} 256 | flag-name: run-${{ matrix.ruby }}-${{ matrix.gemfile }} 257 | parallel: true 258 | 259 | finish: 260 | needs: test 261 | runs-on: ubuntu-latest 262 | steps: 263 | - name: Coveralls Finished 264 | uses: coverallsapp/github-action@main 265 | with: 266 | github-token: ${{ secrets.github_token }} 267 | parallel-finished: true 268 | --------------------------------------------------------------------------------