等待资源完成

时间:2018-04-16 07:32:13

标签: ruby chef

我有一个类似于此的食谱:

...
custom_resource1 "example" do
  writing stuff to a file
end
log 'File found!' do
  message "Found it
  level :info
  notifies :run, 'custom_resource2[example]', :immediately
  only_if { ::File.exists?(file) }
end
...

custom_resource1是一个包含其他资源的大资源,需要一些时间才能完成(迭代某些data_bags并写入文件)。

有时,我发现在厨师运行期间custom_resource1失败,但在食谱失败之前仍会触发custom_resource2

在继续之前,有没有办法确保custom_resource1失败或完成?

2 个答案:

答案 0 :(得分:0)

这是不可能的,Chef使用完全阻塞的执行模型(除了双程加载系统)。每个资源的完整操作方法按顺序运行,没有并发。您必须发布更多代码以隔离实际问题。

答案 1 :(得分:0)

我还认为这很奇怪,因为即使custom_resource2是由通知触发的,也从未打印过日志语句。解决方法是删除日志语句,而是添加:

custom_resource2 "example" do do stuff only_if { ::File.exists?(file) } end

猜猜它与不同的厨师阶段有关

相关问题