Introduction
One common pattern with Azure durable functions is for an orchestrator to call one or more activity functions in order. If these activity functions don't themselves return a value or have any external effect, it can be difficult to follow where the orchestrator function has got to.
To get around this, I have a simple class which is returned for any activity function that does not have its own return type:
public class ActivityResponse
{
public string FunctionName { get; set; }
public string Message { get; set; }
public bool FatalError { get; set; }
}
Then when the durable function is called, it populates this class with the function name and any error or message that should be logged.
[FunctionName("GetLeagueSummaryLogParametersActivity")]
public static async Task<ActivityResponse> GetLeagueSummaryLogParametersActivity(
[ActivityTrigger] DurableActivityContext context,
ILogger log = null)
{
ActivityResponse ret = new ActivityResponse()
{ FunctionName = "GetLeagueSummaryLogParametersActivity" };
try
{
}
catch (Exception ex)
{
if (null != log)
{
log.LogError ($"GetLeagueSummaryLogParametersActivity : error {ex.Message} ");
}
ret.Message = ex.Message;
ret.FatalError = true;
}
return ret;
}
Then the calling function can make use of this returned class and use it with the SetContext
method to add it to the durable function's status message:
ActivityResponse resp = await context.CallActivityAsync<ActivityResponse>
("GetLeagueSummaryLogParametersActivity", queryRequest);
#region Logging
if (null != log)
{
if (null != resp)
{
log.LogInformation($"{resp.FunctionName} complete: {resp.Message } ");
}
}
#endregion
if (null != resp)
{
context.SetCustomStatus(resp);
}
This context message will then be available through the GetStatusAsync method (and will also be logged in Application Insights if you have that hooked up to your functions app.)
History
- 2019-01-02 Initial version