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
Merged

Serialize classes and modules with ActiveJob #37159

merged 1 commit into from Sep 10, 2019

Conversation

kddnewton
Copy link
Contributor

@kddnewton kddnewton 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.
@kaspth kaspth merged commit 8ca1669 into rails:master Sep 10, 2019
2 checks passed
@kaspth
Copy link
Contributor

kaspth commented Sep 10, 2019

LGTM, thanks!

@kddnewton kddnewton deleted the 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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants