函数是:
def createuser(name,pass,time)
puts name,pass,time
end
我试试:
handle_asynchronously :createuser("a","b","c")
得到一个错误:语法错误,意外'(',期待keyword_end
谢谢。
===编辑===
日本的用户数据库和北京的网络服务器。所以我用这种方式来创建用户。
def createuser(name,pass,time)
Net::HTTP.get(URI.parse("http://www.example.net/builduser.php?hao=#{name}&mi=#{pass}&da=#{time}"))
end
最佳答案
您不需要将参数传递给 handle_asynchronously 方法,这只是说明您的方法应该始终传递给 delay_job 的一种方式。
所以在你的例子中:
def create_user(name,pass,time)
puts name,pass,time
end
handle_asynchronously :create_user
完全满足您的需求。 当你打电话时
create_user('john','foo',Time.now)
和调用是一样的
delay.create_user('john','foo',Time.now)
我只是设置了一个测试应用程序来测试答案,这里是延迟作业序列化的可执行处理程序:
--- !ruby/struct:Delayed::PerformableMethod
object: !ruby/ActiveRecord:User
attributes:
name:
pass:
created_at:
updated_at:
method_name: :create_user_without_delay
args:
- John
- foo
- 2011-03-19 10:45:40.290526 -04:00
关于ruby - Delayed_job : how to use handle_asynchronously to work with a function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5362163/