0

我在 /myapp/scripts/myscript.rb 中有一个 ruby ​​script

, 当我运行ruby script/myscript.rb它时它执行得很好,但是我如何从 ruby​​ 脚本中运行这个带有延迟作业的方法?希望这是有道理的

---myscript.rb---

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

def populate

    #do some stuff here

end
handle_asynchronously :populate

我得到一个未定义的方法“handle_asynchronously”错误

4

1 回答 1

1

我认为 handle_asynchronously 仅适用于方法而不适用于顶级函数。也许你可以像这样声明一个模块:

# scripts/myscript.rb
class Tasks
  def populate
    puts "Populating..."
  end
  handle_asynchronously :populate
end
# call it in some function
def my_user_task
  Tasks.new.populate
end
于 2012-06-15T01:01:13.093 回答