Skip to content

ActiveJob overriding queue_adapter in child class affect parent class #16960

@trungpham

Description

@trungpham

queue_adapter is stored as a class variable. So when a child class overrides it, it also modifies the parent class as well. Therefore we cannot choose a different queue adapter at the job class level. Stuck with one global queue adapter until this is fixed. (Hopefully, being locked into one global queue adapter was not an intended feature)

ActiveJob::Base.queue_adapter == :inline #true
class ChildJobOne < ActiveJob::Base
  self.queue_adapter= :delayed_job
end

Active::Base.queue_adapter == :delayed_job #the child job modified the parent's queue_adapter class variable

class ChildJobTwo < ActiveJob::Base
end
ChildJobTwo.queue_adapter == :delayed_job #new child job is also effected as well, no longer using the default :inline adapter

We can fix this by avoid directly using the class variable, instead should use mattr_writer to update the queue_adapter variable.
See https://github.com/rails/rails/blob/master/activejob/lib/active_job/queue_adapter.rb#L12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions