rails - 没有执行方法的延迟作业
rails - Delayed jobs without perform method
在用很多方法做了一个大 class 之后,我希望在延迟的作业中调用所有这些方法。
但是 Delayed::job
的做法是,您必须使用 perform
方法创建一个 class,例如:
class Me < Struct.new(:something)
def perform
puts "GO"
end
end
并这样称呼它:
Delayed::Job.enqueue Me.new(1)
但问题是我的 class 已经有很多这样的方法
class NameHandler
def self.init
ap "TODO : Delayed jobs "
end
def self.action_one
...
end
def self.action_two
...
end
etc.
end
我想这样称呼它:
Delayed::Job.enqueue NameHandler.action_one params...
有最佳实践吗?或者我必须按照 classic Delayed::job 的方式输很多次?
在README中它有多种方式:
Me.new.delay.action_one
或
class NameHandler
handle_asynchronously :action_one
def action_one
end
def self.action_one
new.action_one
end
end
NameHandler.action_one
在用很多方法做了一个大 class 之后,我希望在延迟的作业中调用所有这些方法。
但是 Delayed::job
的做法是,您必须使用 perform
方法创建一个 class,例如:
class Me < Struct.new(:something)
def perform
puts "GO"
end
end
并这样称呼它:
Delayed::Job.enqueue Me.new(1)
但问题是我的 class 已经有很多这样的方法
class NameHandler
def self.init
ap "TODO : Delayed jobs "
end
def self.action_one
...
end
def self.action_two
...
end
etc.
end
我想这样称呼它:
Delayed::Job.enqueue NameHandler.action_one params...
有最佳实践吗?或者我必须按照 classic Delayed::job 的方式输很多次?
在README中它有多种方式:
Me.new.delay.action_one
或
class NameHandler
handle_asynchronously :action_one
def action_one
end
def self.action_one
new.action_one
end
end
NameHandler.action_one