您需要在調用invoke
方法後重新啓用耙子任務,或使用execute
以避免重新啓用。
使用調用,您的代碼可能是這樣的:
def perform
Rake::Task['test:fetch'].invoke("foo", "bar", 1, 1)
Rake::Task['test:fetch'].reenable
Rake::Task['test:fetch'].invoke("foo1", "bar1", 1, 1)
end
使用執行,你的代碼可能是這樣的:
def perform
task_args = {:arg1 => "foo", :arg2 => "bar", :arg3 => 1, :arg4 => 1 }
Rake::Task['test:fetch'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values))
task_args = {:arg1 => "foo1", :arg2 => "bar1", :arg3 => 1, :arg4 => 1 }
Rake::Task['test:fetch'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values)
end
對於一些更多解釋見這裏:Why is Rake not able to invoke multiple tasks consecutively?