zoukankan      html  css  js  c++  java
  • 在Runbook中添加Checkpoint-workflow

    本文说明的是使用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.

  • 相关阅读:
    【JVM】垃圾回收概述(十五)
    mysql命令查看某数据使用空间情况,索引,行数
    联合使用PrediXcan、MetaXcan基于GWAS结果预测靶基因及特异性组织的表达(又名全转录组分析Transcriptome-Wide AnalysisS)
    【Python基础编程009 ● Python入门 ● 输入 】
    【Python基础编程007 ● Python入门 ● 字符串的格式化操作符 】
    【Python基础编程006 ● Python入门 ● 输出的基本使用 】
    【Python基础编程005 ● Python入门 ● 标志符和关键字 】
    【Python基础编程004 ● Python入门 ● 变量的数据类型 】
    【Python基础编程003 ● Python入门 ● 变量的定义及其使用 】
    【Python基础编程002 ● Python入门 ● 注释 】
  • 原文地址:https://www.cnblogs.com/qixue/p/4775165.html
Copyright © 2011-2022 走看看