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

Serialize classes and modules with ActiveJob #37159

Merged
merged 1 commit into from Sep 10, 2019

Conversation

@kddeisz
Copy link
Contributor

commented Sep 9, 2019

This commit allows ActiveJob to serialize classes and modules without a custom serializer. This allows for workflows like:

class EmailJob < ApplicationJob
  queue_as :default
  def perform(template_class, *arguments)
    template_class.new(*arguments).send!
  end
end

module Email
  class FooTemplate ... end
  class BarTemplate ... end
end

EmailJob.perform_later(Email::FooTemplate, ...)
EmailJob.perform_later(Email::BarTemplate, ...)

Currently this is only achieveable through a custom serializer or through constantizing in each instance.

This commit allows ActiveJob to serialize classes and modules without a custom serializer. This allows for workflows like:

```
class EmailJob < ApplicationJob
  queue_as :default
  def perform(template_class, *arguments)
    template_class.new(*arguments).send!
  end
end

module Email
  class FooTemplate ... end
  class BarTemplate ... end
end

EmailJob.perform_later(Email::FooTemplate, ...)
EmailJob.perform_later(Email::BarTemplate, ...)
```

Currently this is only achieveable through a custom serializer or through constantizing in each instance.
@rails-bot rails-bot bot added activejob docs labels Sep 9, 2019
@kaspth kaspth merged commit 8ca1669 into rails:master Sep 10, 2019
2 checks passed
2 checks passed
buildkite/rails Build #63539 passed (18 minutes, 52 seconds)
Details
codeclimate All good!
Details
@kaspth

This comment has been minimized.

Copy link
Member

commented Sep 10, 2019

LGTM, thanks!

@kddeisz kddeisz deleted the kddeisz:serialize-classes branch Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.