Skip to content

idea: way to make it easy to invoke a method on an object #22

@jjb

Description

@jjb

My most common use of sidekiq is

foo.delay.my_method(1,2,3)

This is pretty safe for most things, but it would be more ideal and efficient in some ways to have the worker pull out the object again and then invoke.

class FooMyMethodDoer
  include Sidekiq::Worker

  def perform(id,a,b,c)
    foo = Foo.find(id)
    foo.my_method(a,b,c)
  end
end

So, one could make some sort of generic worker for this

class MethodInvoker
  include Sidekiq::Worker

  def perform(class_name, id, method_name, *params)
    object = class_name.constantize.find(id)
    object.method(method_name.to_sym).run(params)
  end
end

(I haven't tried that, I may have gotten something slightly off)

Would be nice to have some syntactic sugar for that, so instead of instantiating a worker in one's code all the time, one could just do:

foo.delay_awesomely(:my_method, 1,2,3)

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions