protected virtual async Task <Status> handleTelemetrySync(IDurableOrchestrationContext context, ILogger log, StateActionContext stateCtxt) { var synced = Status.GeneralError; // Max telemetry sync cycle var operationTimeoutTime = context.CurrentUtcDateTime.AddMinutes(30); if (!context.IsReplaying) { log.LogInformation($"Instantiating telemtry sync loop for: {stateCtxt.ToJSON()}"); } while (context.CurrentUtcDateTime < operationTimeoutTime) { if (!context.IsReplaying) { log.LogInformation($"Waiting for telemetry sync for: {stateCtxt.ToJSON()}"); } synced = await context.CallActivityAsync <Status>("TelemetrySyncOrchestration_Sync", stateCtxt); if (!synced) { if (!context.IsReplaying) { log.LogInformation($"Error durring sync process: {synced.ToJSON()}"); } // TODO: Need to call another activity to set the State.Telemetry.Enabled = false to keep it in sync, maybe set an error message break; } else { var refreshRate = synced.Metadata.ContainsKey("RefreshRate") ? synced.Metadata["RefreshRate"].ToString().As <int>() : 30; // Wait for the next checkpoint var nextCheckpoint = context.CurrentUtcDateTime.AddSeconds(refreshRate); if (!context.IsReplaying) { log.LogInformation($"Continuing telemtry sync at {nextCheckpoint} for: {stateCtxt.ToJSON()}"); } await context.CreateTimer(nextCheckpoint, CancellationToken.None); } } await context.CallActivityAsync <Status>("TelemetrySyncOrchestration_SetTimeout", stateCtxt); synced = await context.CallActivityAsync <Status>("TelemetrySyncOrchestration_Sync", stateCtxt); return(synced); }
protected virtual async Task <Status> handleCanFinalize(IDurableOrchestrationContext context, ILogger log, StateActionContext stateCtxt) { var canFinalize = Status.GeneralError; var operationTimeoutTime = context.CurrentUtcDateTime.AddMinutes(30); // using (var timeoutCts = new CancellationTokenSource()) // { // while (true) // { if (!context.IsReplaying) { log.LogInformation($"Waiting for organization infrastructure to boot for: {stateCtxt.ToJSON()}"); } // var operationHasTimedOut = context.CurrentUtcDateTime > operationTimeoutTime; // if (operationHasTimedOut) // { // if (!context.IsReplaying) // log.LogError($"Booting organization infrastructure timedout for: {stateCtxt.ToJSON()}"); // context.SetCustomStatus("Organization Booting has timed out, please try again."); // break; // } // // if (!context.IsReplaying) // { // var deadline = context.CurrentUtcDateTime.AddSeconds(10); // if (!context.IsReplaying) // log.LogInformation($"Establishing delay timer until {deadline} for: {stateCtxt.ToJSON()}"); // await context.CreateTimer(deadline, 0, timeoutCts.Token); // } var retryOptions = new RetryOptions(TimeSpan.FromSeconds(10), 360) { Handle = handleRetryException, RetryTimeout = TimeSpan.FromMinutes(30) }; canFinalize = await context.CallActivityWithRetryAsync <Status>("BootOrganizationOrchestration_CanFinalize", retryOptions, stateCtxt); // if (canFinalize) // { // timeoutCts.Cancel(); // break; // } // } // } return(canFinalize); }