public static async Task OrchestratorThrowWithRetry([OrchestrationTrigger] DurableOrchestrationContext ctx) { string message = ctx.GetInput <string>(); RetryOptions options = new RetryOptions(TimeSpan.FromSeconds(5), 3); // This throw happens in the implementation of an orchestrator. await ctx.CallSubOrchestratorWithRetryAsync(nameof(TestOrchestrations.Throw), options, message); }
public static async Task OrchestratorWithRetry_NullRetryOptions([OrchestrationTrigger] DurableOrchestrationContext ctx) { string message = ctx.GetInput <string>(); RetryOptions options = null; // This throw happens in the implementation of an orchestrator. await ctx.CallSubOrchestratorWithRetryAsync(nameof(TestOrchestrations.ThrowOrchestrator), options, message); }
public async Task Run([OrchestrationTrigger] DurableOrchestrationContext context, ILogger log) { var teamModel = context.GetInput <TeamModel>(); if (!teamModel.Initialized) { await context.CallSubOrchestratorWithRetryAsync(nameof(InitializeOrchestrator), _options.AsRetryOptions(), teamModel); teamModel.Initialized = true; } try { var weeks = context.CurrentUtcDateTime.Date .Range(_options.PastWeeks, _options.FutureWeeks, _options.StartDayOfWeek); var weekTasks = weeks .Select(startDate => new WeekModel { StartDate = startDate, StoreId = teamModel.StoreId, TeamId = teamModel.TeamId }) .Select(weekModel => context.CallSubOrchestratorWithRetryAsync(nameof(WeekOrchestrator), _options.AsRetryOptions(), weekModel)); await Task.WhenAll(weekTasks); } catch (Exception ex) when(_options.ContinueOnError) { log.LogTeamError(ex, teamModel); } if (_options.FrequencySeconds < 0) { return; } var dueTime = context.CurrentUtcDateTime.AddSeconds(_options.FrequencySeconds); await context.CreateTimer(dueTime, CancellationToken.None); context.ContinueAsNew(teamModel); }
public static async Task OrchestratorThrowWithRetry([OrchestrationTrigger] DurableOrchestrationContext ctx) { string message = ctx.GetInput <string>(); RetryOptions options = new RetryOptions(TimeSpan.FromSeconds(5), 3); // Specify an explicit sub-orchestration ID that can be queried by the test driver. Guid subInstanceId = await ctx.CallActivityAsync <Guid>(nameof(TestActivities.NewGuid), null); ctx.SetCustomStatus(subInstanceId.ToString("N")); // This throw happens in the implementation of an orchestrator. await ctx.CallSubOrchestratorWithRetryAsync( nameof(TestOrchestrations.ThrowOrchestrator), options, subInstanceId.ToString("N"), message); }
public static async Task <Get_League_Summary_Definition_Return> OnGetLeagueSummaryQueryHandlerOrchestrator ([OrchestrationTrigger] DurableOrchestrationContext context, Microsoft.Extensions.Logging.ILogger log) { // Get the query definition form the context... QueryRequest <Get_League_Summary_Definition> queryRequest = context.GetInput <QueryRequest <Get_League_Summary_Definition> >(); try { if (null != queryRequest) { if (string.IsNullOrWhiteSpace(queryRequest.QueryName)) { queryRequest.QueryName = "Get League Summary"; } // Log the query request in its own own query event stream Guid queryId = await context.CallActivityWithRetryAsync <Guid>("GetLeagueSummaryCreateQueryRequestActivity", DomainSettings.QueryRetryOptions(), queryRequest); if (queryId.Equals(Guid.Empty)) { #region Logging if (null != log) { // Unable to get the request details from the orchestration log.LogError("OnGetLeagueSummaryQueryHandlerOrchestrator : Unable to create the query event stream"); } #endregion return(null); } else { queryRequest.QueryUniqueIdentifier = queryId; // Save the parameters to the event stream ActivityResponse resp = null; resp = await context.CallActivityWithRetryAsync <ActivityResponse>("GetLeagueSummaryLogParametersActivity", DomainSettings.QueryRetryOptions(), queryRequest); #region Logging if (null != log) { if (null != resp) { log.LogInformation($"{resp.FunctionName} complete: {resp.Message } "); } } #endregion if (null != resp) { context.SetCustomStatus(resp); } // next validate the query bool valid = false; try { valid = await context.CallActivityWithRetryAsync <bool>("GetLeagueSummaryValidateActivity", DomainSettings.QueryRetryOptions(), queryRequest); } catch (FunctionFailedException ffs) { if (null == resp) { resp = new ActivityResponse() { FunctionName = "QueryProjectionProcessorOrchestrator" }; } resp.Message = ffs.Message; resp.FatalError = true; } if (!valid) { #region Logging if (null != log) { // Could not run the query as the parameters don't make sense log.LogError($"OnGetLeagueSummaryQueryHandlerOrchestrator : Query parameters are invalid {queryId}"); } #endregion return(null); } else { try { // Request all the projections needed to answer this query resp = await context.CallActivityWithRetryAsync <ActivityResponse>("GetLeagueSummaryQueryProjectionRequestActivity", DomainSettings.QueryRetryOptions(), queryRequest); } catch (FunctionFailedException ffs) { if (null == resp) { resp = new ActivityResponse() { FunctionName = "QueryProjectionProcessorOrchestrator" }; } resp.Message = ffs.Message; resp.FatalError = true; } if (null != resp) { #region Logging if (null != log) { if (null != resp) { log.LogInformation($"{resp.FunctionName} complete: {resp.Message } "); } } #endregion context.SetCustomStatus(resp); if (resp.FatalError) { #region Logging if (null != log) { log.LogError($"Fatal error in {resp.FunctionName} - {resp.Message} "); } #endregion return(null); } } // Get all the outstanding projection requests by calling a sub-orchestrator Query_Projections_Projection_Request projectionQueryRequest = new Query_Projections_Projection_Request() { UniqueIdentifier = queryRequest.QueryUniqueIdentifier.ToString(), QueryName = queryRequest.QueryName }; try { resp = await context.CallSubOrchestratorWithRetryAsync <ActivityResponse>("QueryProjectionProcessorOrchestrator", DomainSettings.QueryRetryOptions(), projectionQueryRequest); } catch (FunctionFailedException ffs) { if (null == resp) { resp = new ActivityResponse() { FunctionName = "QueryProjectionProcessorOrchestrator" }; } resp.Message = ffs.Message; resp.FatalError = true; } if (null != resp) { #region Logging if (null != log) { if (null != resp) { log.LogInformation($"{resp.FunctionName} complete: {resp.Message } "); } } #endregion context.SetCustomStatus(resp); if (resp.FatalError) { #region Logging if (null != log) { log.LogError($"Fatal error in {resp.FunctionName} - {resp.Message} "); } #endregion return(null); } } try { // Output the results resp = await context.CallActivityWithRetryAsync <ActivityResponse>("GetLeagueSummaryOutputResultsActivity", DomainSettings.QueryRetryOptions(), queryRequest); } catch (FunctionFailedException ffs) { if (null == resp) { resp = new ActivityResponse() { FunctionName = "QueryProjectionProcessorOrchestrator" }; } resp.Message = ffs.Message; resp.FatalError = true; } #region Logging if (null != log) { if (null != resp) { log.LogInformation($"{resp.FunctionName} complete: {resp.Message } "); } } #endregion if (null != resp) { context.SetCustomStatus(resp); if (resp.FatalError) { #region Logging if (null != log) { log.LogError($"Fatal error in {resp.FunctionName} - {resp.Message} "); } #endregion return(null); } } // Get the results for ourselves to return...to do this the query must be complete... Get_League_Summary_Definition_Return ret = await context.CallActivityWithRetryAsync <Get_League_Summary_Definition_Return>("GetLeagueSummaryGetResultsActivity", DomainSettings.QueryRetryOptions(), queryRequest); return(ret); } } } else { if (null != log) { // Unable to get the request details from the orchestration log.LogError("OnGetLeagueSummaryQueryHandlerOrchestrator : Unable to get the query request from the context"); string contextAsString = context.GetInput <string>(); if (!string.IsNullOrWhiteSpace(contextAsString)) { log.LogError($"Context was {contextAsString} "); } else { log.LogError($"Context was blank "); } } return(null); } } catch (Exception ex) { #region Logging if (null != log) { // Error running thew orchestration log.LogError($"OnGetLeagueSummaryQueryHandlerOrchestrator : Error {ex.Message}"); } #endregion if (null != context) { context.SetCustomStatus($"OnGetLeagueSummaryQueryHandlerOrchestrator : Error {ex.Message}"); } throw; } }
public static async Task <object> BliNyKunde( [OrchestrationTrigger] DurableOrchestrationContext ctx, //Dette forteller Azure at dette er en Orchestrator function TraceWriter log) //Azure function writer { var firmanavn = ctx.GetInput <string>(); string kundenummerTemp = null; string kundenummer = null; string kontonummer = null; var saksResultat = "Unknown"; var aksjekapitalResultat = "Unknown"; var signeringsResultat = "Unknown"; try { //Chaining Functions //Init if (!ctx.IsReplaying) { log.Info("A_InitNyKunde aktivitet kalles for firma:" + firmanavn); } kundenummerTemp = await ctx.CallActivityAsync <string>("A_InitNyKunde", firmanavn); //Opprett driftskonto kontonummer = await ctx.CallActivityAsync <string>("A_OpprettDriftskonto", kundenummerTemp); if (false) { //Innbetaling av aksjekapital var aksjeKapitalSjekkRetries = await ctx.CallActivityAsync <int>("A_GetAksjekapitalRetries", null); aksjekapitalResultat = await ctx.CallSubOrchestratorAsync <string>("O_SendOgSjekkAksjekapitalWithRetry", aksjeKapitalSjekkRetries); if (aksjekapitalResultat != "BeløpInnbetalt") { if (!ctx.IsReplaying) { log.Info("Innbetaling ikke utført i tide, sak avsluttes"); } saksResultat = await ctx.CallActivityAsync <string>("A_RyddOgAvsluttSak", kundenummerTemp); return(new { KundenummerTemp = kundenummerTemp, Kontonummer = kontonummer, AksjekapitalResultat = aksjekapitalResultat, SaksResultat = saksResultat }); } } if (false) { //Signering if (!ctx.IsReplaying) { log.Info("O_SendOgSjekkSigneringWithRetry kalles"); } var signeringsRetries = await ctx.CallActivityAsync <int>("A_GetSigneringsRetries", null); signeringsResultat = await ctx.CallSubOrchestratorAsync <string>("O_SendOgSjekkSigneringWithRetry", signeringsRetries); if (signeringsResultat != "AlleHarSignert") { if (!ctx.IsReplaying) { log.Info("Signering ikke utført i tide, sak avsluttes"); } saksResultat = await ctx.CallActivityAsync <string>("A_RyddOgAvsluttSak", kundenummerTemp); //Stopp videre behandling return(new { KundenummerTemp = kundenummerTemp, Kontonummer = kontonummer, AksjekapitalResultat = aksjekapitalResultat, SigneringsResultat = signeringsResultat, SaksResultat = saksResultat }); } if (!ctx.IsReplaying) { log.Info("Kunde opprettet i banken!! Velkommen som kunde."); } saksResultat = "Kundeforhold opprettet."; if (false) { //Signering if (!ctx.IsReplaying) { log.Info("O_SendSignering kalles"); } //var signeringResults = // await ctx.CallSubOrchestratorAsync<string[]>("O_Signering", "00986333111"); //Retry upto 2 times with 35 seconds delay between each attempt var signeringResults = await ctx.CallSubOrchestratorWithRetryAsync <string[]>("O_SendSignering", new RetryOptions(TimeSpan.FromSeconds(35), 2), "00986333111"); //Only retry invalid operation Exception //var signeringResults = // await ctx.CallSubOrchestratorWithRetryAsync<string[]>("O_Signering", new RetryOptions(TimeSpan.FromSeconds(35), 2) // { Handle = ex => ex is InvalidOperationException }, "00986333111"); } } } catch (Exception e) { if (!ctx.IsReplaying) { log.Error($"Caught an error from an activity: {e.Message}"); } await ctx.CallActivityAsync <string>("A_RyddOgAvsluttSak", kundenummerTemp); return(new { Error = "Failed to process BliNyKunde", Message = e.Message }); } return(new { KundenummerTemp = kundenummerTemp, Kontonummer = kontonummer, AksjekapitalResultat = aksjekapitalResultat, SigneringsResultat = signeringsResultat, SaksResultat = saksResultat }); }
public static async Task <object> Workflow( [OrchestrationTrigger] DurableOrchestrationContext ctx, TraceWriter log) { log.Info("Orchestrator function processed a request."); EventInfo first = null; EventInfo[] second = null; EventInfo last = null; string approval = "UNKNOWN"; // Retry up to 4 times with 5 second delay between each attempt var retryOptions = new RetryOptions(TimeSpan.FromSeconds(5), 4) { Handle = ex => ex is InvalidOperationException }; // Retrieve Input Argument; var eventId = ctx.GetInput <int>(); try { // Activity 1 if (!ctx.IsReplaying) { log.Info("Execute Activity 1 in serial"); } first = await ctx.CallActivityWithRetryAsync <EventInfo>("A_Activity1", retryOptions, eventId); first.OrchestrationId = ctx.InstanceId; // SubOrchestration 1 second = await ctx.CallSubOrchestratorWithRetryAsync <EventInfo[]>("O_SubWorkFlow1", retryOptions, eventId); //SubOrchestration 1 last = await ctx.CallSubOrchestratorWithRetryAsync <EventInfo>("O_SubWorkFlow2", retryOptions, eventId); } catch (Exception e) { // Cleanup if (!ctx.IsReplaying) { log.Info($"Caught an error from an activity: { e.Message}"); } await ctx.CallActivityAsync <string>("A_Cleanup", new[] { eventId }); return(new { Error = "Failed to process Workflow", e.Message }); } return(new { First = first, Second = second, Last = last }); }