运行 使用 .NET SDK 监控 ADF 管道 运行
Run & monitor ADF pipeline run using .NET SDK
我使用 Azure 数据工厂 UI 创建了一个 ADF 管道,它每天触发一次 运行。 有没有办法使用 .NET SDK 获取最新的管道 运行 id 并监控 运行? 请提供一个与现有 ADF 执行相同操作的控制台应用程序管道 运行?
这是我在使用 .NET SDK 创建管道和监视器时尝试的方法 运行 (https://docs.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;
}
}
但是是否可以通过从 ADF 获取最新的 运行 ID 来监控 运行?
第一步,请看IPipelineRunsOperations.QueryByFactoryWithHttpMessagesAsync方法。
第 2 步:导航到 RunFilterParameters Class,您可以找到名为 OrderBy 的 属性。
第 3 步:找到 RunQueryOrderBy Class,您可以看到它接受 2 个参数。在这里,您可以将它们设置为 RunEnd
和 DESC
.
第 4 步:只需获取管道运行列表的第一个元素。
我使用 Azure 数据工厂 UI 创建了一个 ADF 管道,它每天触发一次 运行。 有没有办法使用 .NET SDK 获取最新的管道 运行 id 并监控 运行? 请提供一个与现有 ADF 执行相同操作的控制台应用程序管道 运行?
这是我在使用 .NET SDK 创建管道和监视器时尝试的方法 运行 (https://docs.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;
}
}
但是是否可以通过从 ADF 获取最新的 运行 ID 来监控 运行?
第一步,请看IPipelineRunsOperations.QueryByFactoryWithHttpMessagesAsync方法。
第 2 步:导航到 RunFilterParameters Class,您可以找到名为 OrderBy 的 属性。
第 3 步:找到 RunQueryOrderBy Class,您可以看到它接受 2 个参数。在这里,您可以将它们设置为 RunEnd
和 DESC
.
第 4 步:只需获取管道运行列表的第一个元素。