加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 任务依赖是否始终以耙子的特定顺序运行?

发布时间:2020-12-17 01:21:03 所属栏目:百科 来源:网络整理
导读:我有以下示例是基于我想要我的rakefile使用的结构: task :default do puts 'Tasks you can run: dev,stage,prod'endtask :dev = [:init,:devrun,:clean]task :devrun do puts 'Dev stuff'endtask :stage = [:init,:stagerun,:clean]task :stagerun do puts
我有以下示例是基于我想要我的rakefile使用的结构:
task :default do
    puts 'Tasks you can run: dev,stage,prod'
end

task :dev => [:init,:devrun,:clean]
task :devrun do
    puts 'Dev stuff'
end

task :stage => [:init,:stagerun,:clean]
task :stagerun do
    puts 'Staging stuff'
end

task :prod => [:init,:prodrun,:clean]
task :prodrun do
    puts 'Production stuff'
end

task :init do
    puts 'Init...'
end

task :clean do
    puts 'Cleanup'
end

任务总是按照相同的顺序运行吗?我读到某个地方,他们不会,还有别的地方,所以我不知道.

或者,如果您可以建议一个更好的方法来做我正在尝试实现的(例如,有一个常见的初始化和清理步骤围绕依赖环境的步骤),那也是很好的.

谢谢

解决方法

从耙源码:
# Invoke all the prerequisites of a task.
def invoke_prerequisites(task_args,invocation_chain) # :nodoc:
  @prerequisites.each { |n|
    prereq = application[n,@scope]
    prereq_args = task_args.new_scope(prereq.arg_names)
    prereq.invoke_with_call_chain(prereq_args,invocation_chain)
  }
end

所以看起来,代码通常只是迭代数组并顺序运行必备任务.

然而:

# Declare a task that performs its prerequisites in parallel. Multitasks does
# *not* guarantee that its prerequisites will execute in any given order
# (which is obvious when you think about it)
#
# Example:
#   multitask :deploy => [:deploy_gem,:deploy_rdoc]
#
def multitask(args,&block)
  Rake::MultiTask.define_task(args,&block)
end

所以你是对的,都可以是真的,但是只有在你的任务前面加上多任务的时候,命令才能被关掉它看起来像是常规的任务按顺序运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读