user989988
user989988

Reputation: 3746

Run & monitor ADF pipeline run using .NET SDK

I created an ADF pipeline using the Azure Data Factory UI that triggers a run once every day. Is there a way to get latest pipeline run id & monitor that run using .NET SDK? Please provide a console application that does the same with an existing ADF pipeline run?

This is what I tried where a pipeline is created using .NET SDK and monitor run (https://learn.microsoft.com/en-us/azure/data-factory/quickstart-create-data-factory-dot-net):

static async Task Main(string[] args)
        {
            // Authenticate and create a data factory management client
             var context = new AuthenticationContext("https://login.windows.net/" + tenantID);
             ClientCredential cc = new ClientCredential(applicationId, authenticationKey);
             AuthenticationResult result = context.AcquireTokenAsync(
    "https://management.azure.com/", cc).Result;
             ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);

            using (var client = new DataFactoryManagementClient(cred) { 
                      SubscriptionId = subscriptionId 
              })
            {
                RunQueryFilter filter1 = new RunQueryFilter("PipelineName", "Equals", new List<string> { "Pipeline" });                
                DateTime before = DateTime.UtcNow;
                DateTime after = before.AddHours(-24);
                RunFilterParameters param = new RunFilterParameters(after, before, null, new List<RunQueryFilter> { filter1 }, null);
                PipelineRunsQueryResponse pipelineResponse = client.PipelineRuns.QueryByFactory(
                                                                        resourceGroup,
                                                                        dataFactoryName, param
                                                                    );

            }



            // Monitor the pipeline run
            Console.WriteLine("Checking pipeline run status...");
            PipelineRun pipelineRun;
            while (true)
            {
                pipelineRun = client.PipelineRuns.Get(
                   resourceGroup, dataFactoryName, runResponse.RunId);
                Console.WriteLine("Status: " + pipelineRun.Status);
                if (pipelineRun.Status == "InProgress" || pipelineRun.Status == "Queued")
                    System.Threading.Thread.Sleep(15000);
                else
                    break;
            }
}

but is it possible to monitor the run by getting latest run id from ADF?

Upvotes: 1

Views: 1212

Answers (1)

Jay Gong
Jay Gong

Reputation: 23792

Step1,please see IPipelineRunsOperations.QueryByFactoryWithHttpMessagesAsync method.

enter image description here

Step2: Navigate to RunFilterParameters Class, you could find the property named OrderBy.

enter image description here

Step3: Find RunQueryOrderBy Class and you could see it accepts 2 parameters. Here, you could set them as RunEnd and DESC.

enter image description here

Step4: Just get the first element of the Pipeline Runs List.

Upvotes: 1

Related Questions