Last active
August 8, 2018 21:01
-
-
Save abelorian/b641ca79c6e4d1dac6864f6560ee9009 to your computer and use it in GitHub Desktop.
Generic Worker Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To do: add validations | |
class GenericWorker < ApplicationWorker | |
def perform(options) | |
klass = options["klass"].constantize | |
if options["id"].present? | |
if options[:params].present? | |
klass.find(options["id"]).send options["method_name"], options["params"] | |
else | |
klass.find(options["id"]).send options["method_name"] | |
end | |
else | |
if options[:params].present? | |
klass.send options["method_name"], options["params"] | |
else | |
klass.send options["method_name"] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment