Azure functions 如何在Azure持久函数中持久化变量
我创建了一个AzureAzure functions 如何在Azure持久函数中持久化变量,azure-functions,azure-durable-functions,Azure Functions,Azure Durable Functions,我创建了一个Azure持久功能,它似乎工作得很好,但是我有一个while循环,这让我头疼 这是我的持久功能: [FunctionName("Function1")] public static async Task<string> RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) {
持久功能
,它似乎工作得很好,但是我有一个while循环,这让我头疼
这是我的持久功能:
[FunctionName("Function1")]
public static async Task<string> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
var output = string.Empty;
bool resumed = false;
var powerBIAuth = await context.CallActivityAsync<AzureAuthentication>("PowerBIAuthenticate", "");
// here generate the report
var response = await context.CallActivityAsync<ResponseRequestReport>("GenerateReport", powerBIAuth.access_token);
if(response != null)
{
response.token = powerBIAuth.access_token;
while (true)
{
//***PROBLEM HAPPENS HERE*****//
//***The second time it tries after the sleep, the response variable that I pass to the function is null.. why? *****//
response = await context.CallActivityAsync<ResponseRequestReport>("ReportStatus", response);
if(response.percentComplete == 100)
{
break;
}
// Orchestration sleeps until this time.
var nextCheck = context.CurrentUtcDateTime.AddSeconds(20);
await context.CreateTimer(nextCheck, CancellationToken.None);
}
}
return output;
}
[FunctionName(“Function1”)]
公共静态异步任务RunOrchestrator(
[OrchestrationTrigger]IDurableOrchestrationContext(上下文)
{
var输出=string.Empty;
bool=false;
var powerBIAuth=await context.CallActivityAsync(“PowerBIAuthenticate”,”);
//在这里生成报告
var response=wait context.CallActivityAsync(“GenerateReport”,powerBIAuth.access\u令牌);
if(响应!=null)
{
response.token=powerBIAuth.access\u令牌;
while(true)
{
//***问题发生在这里*****//
//***在休眠后第二次尝试时,我传递给函数的响应变量为null。为什么*****//
response=wait context.CallActivityAsync(“ReportStatus”,response);
如果(response.percentComplete==100)
{
打破
}
//编排将一直休眠到此时。
var nextCheck=context.CurrentUtcDateTime.AddSeconds(20);
wait context.CreateTimer(nextCheck,CancellationToken.None);
}
}
返回输出;
}
如果您看到代码,首先要做的事情是等待,直到我获得一个令牌,然后调用其他函数生成一个报告,然后再执行一段时间,以等待报告完成
我第一次检查response
变量的状态时,它有一个值,第二次在睡眠后尝试传递给ReportStatus
函数的response
变量是null
,由于为null,该函数中的所有代码都会崩溃
为什么呢?我做错了什么?似乎在睡眠之后,编排器丢失了局部变量的持久性。这让我头疼
有什么线索吗?您应该了解的一件事是DF不会持久化局部变量。它只保存发送到活动等的数据,因此它可以重播您的代码,从历史记录表中读取结果,并分配变量,就像活动是一个方法调用一样。也就是说,代码看起来确实可以工作。。您能检查一下您在第一次ReportStatus活动调用中是否实际返回了数据吗?您应该了解的一点是DF不会持久化局部变量。它只保存发送到活动等的数据,因此它可以重播您的代码,从历史记录表中读取结果,并分配变量,就像活动是一个方法调用一样。也就是说,代码看起来确实可以工作。。您是否可以检查在第一次ReportStatus活动调用中是否实际返回了数据?