标签:
本文说明的是使用Checkpoint-workflow的一种场景(当然还有其他场景需要Checkpoint-workflow)。
起因:Windows Azure对Automation账户中的Runbook运行时长限制了30minutes。
机制:就是如果你的脚本在30minutes内没有运行完成, 那么执行脚本的Worker会暂定你的脚本,去处理其他账户的任务。
问题:当下一个Worker再来执行您的脚本时,是从最近一次的Checkpoint开始的。如果你未能在脚本执行过程中设置Checkpoint而你的脚本执行时长又大于30minutes,那边你的脚本每次都会从头开始。
这样,永无止境的执行下去,直到系统检测到这种情况并给你抛出异常。
The job cannot continue running because it was repeatedly evicted from the same checkpoint. Please make sure your Runbook does not perform lengthy operations without persisting its state.
Checkpoint Workflow
<Activity1> Checkpoint-Workflow <Activity2> <Error> <Activity3>
注意的是Checkpoint-Workflow不能放在Inlinescript当中。
关于Checkpoint,参考 http://azure.microsoft.com/en-us/blog/azure-automation-reliable-fault-tolerant-runbook-execution-using-checkpoints/
some good points about checkpoint-workflow from Runbook concepts(https://technet.microsoft.com/en-us/library/Dn469257.aspx)
You can set a checkpoint in a workflow with the Checkpoint-Workflow activity. When you include this activity in a runbook, a checkpoint is immediately taken. If the runbook is suspended by an error, when the job is resumed, it will resume from the point of the last checkpoint set.
Some good points about InlineScript
The InlineScript activity runs a block of commands in a separate, non-workflow session and returns its output to the workflow. While commands in a workflow are sent to Windows Workflow Foundation for processing, commands in an InlineScript block are processed by Windows PowerShell. The activity uses the standard workflow common parameters including PSComputerName and PSCredential which allow you to specify that the code block be run on another computer or using alternate credentials.
While InlineScript activities may be critical in certain runbooks, they should only be used when necessary for the following reasons:
You cannot use checkpoints from within an InlineScript block. If a failure occurs within the block, it must be resumed from the beginning.
InlineScript affects scalability of the runbook since it holds the Windows PowerShell session for the entire length of the InlineScript block.
Activities such as Get-AutomationVariable and Get-AutomationPSCredential are not available in an InlineScript block.
you do need to use an InlineScript, you should minimize its scope. For example, if your runbook iterates over a collection while applying the same operation to each item, the loop should occur outside of the InlineScript. This will provide the following advantages:
You can checkpoint the workflow after each iteration. If the job is suspended or interrupted and resumed, the loop will be able to resume.
You can use ForEach –Parallel to handle collection items concurrently.
Keep the following recommendations in mind if you do use an InlineScript in your runbook:
You can pass values into the script though with the $Using scope modifier. For example, a variable called $abc that has been set outside of the InlineScript would become $using:abc inside an InlineScript.
To return output from an InlineScript, assign the output to a variable and output any data to be returned to the output stream. The following example assigns the string “hi” to a variable called $output.
$output = InlineScript { Write-Output "hi" }
Avoid defining workflows within InlineScript scope. Even though some workflows may appear to operate correctly, this is not a tested scenario. As a result, you may encounter confusing error messages or unexpected behavior.
在Runbook中添加Checkpoint-workflow
标签:
原文地址:http://www.cnblogs.com/qixue/p/4775165.html