active_job-performs icon indicating copy to clipboard operation
active_job-performs copied to clipboard

Create jobs for collections / on class level?

Open doits opened this issue 9 months ago • 7 comments

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!

doits avatar Mar 20 '25 18:03 doits