【问题标题】:How to check current status of a Data Factory pipelinerun with just Pipeline name?如何仅使用管道名称检查数据工厂管道运行的当前状态?
【发布时间】:2020-06-02 05:58:41
【问题描述】:

是否可以通过 Powershell 或 API 仅使用管道名称检查 Azure 数据工厂管道运行的当前状态?

我看到您可以使用 Get-AzDataFactoryV2PipelineRun 但这需要您拥有 pipelinerunid。

我的目标是构建一个脚本,该脚本将首先检查管道运行是否正在运行,如果没有触发它。我想避免脚本触发pipelinerun,这样会有多个pipeline同时运行。

【问题讨论】:

    标签: powershell azure-data-factory azure-data-factory-2


    【解决方案1】:

    我已经用 PowerShell 完成了,虽然我确信有更好的方法,但这是我想出的解决方案。

    它基本上获取从一周前到今天的所有管道运行 id,遍历每一个,如果它找到一个“InProgress”,它不会做任何事情。如果没有管道运行 id 处于该状态,则执行它。

    您显然需要事先经过身份验证才能运行:

    $before = get-date
    $after = (get-date).AddDays(-7)
    $runIds = Get-AzDataFactoryV2PipelineRun -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName -LastUpdatedAfter $after -LastUpdatedBefore 
    $before
    $shouldRun = 1
    
    $runIds | ForEach-Object {
        ## Check for all statuses
        if($_.Status -eq "InProgress"){
            $shouldRun = 0
        }
    }
    
    if($shouldRun){
        ## Logic to run pipeline, this is just an example.
        Invoke-AzDataFactoryV2Pipeline -PipelineName $PipelineName -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName
    } 
    

    【讨论】:

      【解决方案2】:

      使用 .Net Core SDK

      ServiceClientCredentials cred = new TokenCredentials(accessToken);
      using (var client = new DataFactoryManagementClient(cred) { SubscriptionId = subscriptionId })
      {
          RunQueryFilter filter1 = new RunQueryFilter("PipelineName", "Equals", new List<string> { "ActualPipelineName" });
          RunQueryFilter filter2 = new RunQueryFilter("Status", "Equals", new List<string> { "Queued" });
          DateTime before = DateTime.UtcNow;
          DateTime after = before.AddHours(-4);
          RunFilterParameters param = new RunFilterParameters(after, before, null, new List<RunQueryFilter> { filter1, filter2 }, null);
          PipelineRunsQueryResponse pipelineResponse = client.PipelineRuns.QueryByFactory(resourceGroupName, azureDataFactoryName, param);
          int? QueuedPipelines = pipelineResponse?.Value?.Count;
      }
      

      在过滤器 1 中,您可以使用“In”运算符查询多个 PipelineName。

      在 filter2 中,您可以使用 ADF 的任何有效状态(Success、InProgress、Queued 等)

      同样的事情也可以使用 REST API 来实现。

      P.S- 如果管道数超过 100(对于该特定状态),您可能需要使用 Continuation 令牌。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-25
        • 1970-01-01
        • 1970-01-01
        • 2018-10-03
        • 2021-07-15
        • 2018-05-12
        • 2017-01-08
        • 1970-01-01
        相关资源
        最近更新 更多