Skip to content

Instantly share code, notes, and snippets.

@xximjasonxx
Created February 16, 2021 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xximjasonxx/30793e0c0c8a21838b0189228c58b3f0 to your computer and use it in GitHub Desktop.
Save xximjasonxx/30793e0c0c8a21838b0189228c58b3f0 to your computer and use it in GitHub Desktop.
[FunctionName("Cleanup_DurableFunctionInstances")]
public async Task Cleanup_DurableFunctionInstances(
[QueueTrigger(Constants.QUEUE_DURABLE_FUNCTION_CLEANUP, Connection = Constants.TABLE_STORAGE_CONNECTION)] string instanceId,
[DurableClient] IDurableOrchestrationClient client,
ILogger logger)
{
try
{
var result = await client.PurgeInstanceHistoryAsync(instanceId);
if (result?.InstancesDeleted > 0)
{
logger.LogInformation($"Successfully purged ${result.InstancesDeleted} workflow instances for Id {instanceId}");
}
else
{
logger.LogWarning($"Attempted to purge the non-existent Durable Function context instance of {result}");
}
}
catch (Exception ex)
{
logger.LogError(ex, $"Failed to clean up instance {instanceId}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment