active_job-performs
active_job-performs copied to clipboard
Create jobs for collections / on class level?
Is there a way to create a job for a collection so that no instance is needed?
For example to publish a collection, something like this:
class Post
performs_on_collection :publish
# class method which receives a collection as first argument by definition
def self.publish(collection, some_arg: nil)
# ...
end
end
Post.where(ready: true).publish_later(some_arg: 'xxx')
# performs `Post.publish(Post.where(ready: true), some_arg: 'xxx')` in a background job
Maybe it is already possible with some ruby magic?
Thanks for your help!