Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use ActiveRecord::Base as parent class #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/delayed/backend/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ def self.configure
yield(configuration)
end

class Base < ::ActiveRecord::Base
self.abstract_class = true
end

# A job object that is persisted to the database.
# Contains the work object as a YAML field.
class Job < ::ActiveRecord::Base
class Job < Base
include Delayed::Backend::Base

if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity)
Expand All @@ -46,7 +50,7 @@ class Job < ::ActiveRecord::Base
before_save :set_default_run_at

def self.set_delayed_job_table_name
delayed_job_table_name = "#{::ActiveRecord::Base.table_name_prefix}delayed_jobs"
delayed_job_table_name = "#{Base.table_name_prefix}delayed_jobs"
self.table_name = delayed_job_table_name
end

Expand All @@ -62,11 +66,11 @@ def self.ready_to_run(worker_name, max_run_time)
end

def self.before_fork
::ActiveRecord::Base.connection_handler.clear_all_connections!
Base.connection_handler.clear_all_connections!
end

def self.after_fork
::ActiveRecord::Base.establish_connection
Base.establish_connection
end

# When a worker is exiting, make sure we don't have any locked jobs.
Expand Down Expand Up @@ -183,7 +187,7 @@ def self.default_timezone
if ::ActiveRecord.respond_to?(:default_timezone)
::ActiveRecord.default_timezone
else
::ActiveRecord::Base.default_timezone
Base.default_timezone
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/delayed/backend/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
describe Delayed::Backend::ActiveRecord::Job do
it_behaves_like "a delayed_job backend"

it "is a descendant of Delayed::Backend::ActiveRecord::Base" do
expect(described_class).to be < Delayed::Backend::ActiveRecord::Base
end

describe "configuration" do
describe "reserve_sql_strategy" do
let(:configuration) { Delayed::Backend::ActiveRecord.configuration }
Expand Down