public static async Task CreateSiteResources( [OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log) { CreationParameters creationParams = context.GetInput <CreationParameters>(); if (!context.IsReplaying) { log.LogWarning("ORC - Creating Site Resources in: {resourceGroup}", creationParams.ResourceGroupName); } // site resources (sql server, sql db, redis cache, storageAccount (record attachments), ???) var storageRequest = CreateStorageAccountRequest.FromCreationParams(creationParams); storageRequest.StorageAccountName = ResourceCreationActivities.GenerateStorageAccountName(creationParams, string.Empty); var t1 = context.CallSubOrchestratorAsync(nameof(CreateSiteSqlServerAndDatabase), creationParams); var t2 = context.CallActivityAsync <CreateStorageAccountResult>(nameof(ResourceCreationActivities.CreateStorageAccount), storageRequest); await Task.WhenAll(t1, t2); if (!context.IsReplaying) { log.LogWarning($"ORC - Created Storage Account Name: {t2.Result.StorageAccountName} - Primary Key: {t2.Result.PrimaryKey.KeyName}, {t2.Result.PrimaryKey.Value}"); log.LogWarning($"ORC - Created Site Resources in Resource Group: {creationParams.ResourceGroupName}"); } }
public static async Task CreateResourcesOrchestrator( [OrchestrationTrigger] DurableOrchestrationContextBase context) { CreationParameters creationParams = context.GetInput <CreationParameters>(); // customer resources --> // create resource group & register resource providers in subscription // create app service plan (prod & dev share the same service plan) // register wildcard SSL certificates // create storage account for http and application logs from webapps // <shortname>logs<prefix-hash> // create blob2sumo webjob // create webapp router // aws setup await context.CallSubOrchestratorAsync(nameof(CreateCustomerResources), creationParams); // site resources (sql server, sql db, cache, storageAccount (record attachments), ???) await context.CallSubOrchestratorAsync(nameof(CreateSiteResources), creationParams); // link resources (all the web apps) }
public static async Task CreateCustomerResources( [OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log) { CreationParameters creationParams = context.GetInput <CreationParameters>(); if (!context.IsReplaying) { log.LogWarning("ORC - Creating Customer Resources in: {resourceGroup}", creationParams.ResourceGroupName); } // Resource Group and Resource Providers if (!context.IsReplaying) { log.LogWarning("ORC - Waiting for Resource Group + Providers"); } await context.CallSubOrchestratorAsync(nameof(CreateCustomerResourceGroup), creationParams); // App Serice Plan and Log Storage Account if (!context.IsReplaying) { log.LogWarning("ORC - Waiting for ASP + Storage Account"); } await context.CallSubOrchestratorAsync(nameof(CreateCoreResources), creationParams); // WebApp Router + AWS Setup can be done as two tasks running in parallel Task[] finalTasks = { context.CallSubOrchestratorAsync(nameof(CreateWebAppRouter), creationParams), context.CallSubOrchestratorAsync(nameof(PerformAwsSetup), creationParams) }; await Task.WhenAll(finalTasks); if (!context.IsReplaying) { log.LogWarning($"ORC - Created Customer Resources in Resource Group: {creationParams.ResourceGroupName}"); } }
public static async Task <List <string> > Run( [OrchestrationTrigger] DurableOrchestrationContextBase context) { const int totalOfProcesses = 20; var tasks = new Task <string> [totalOfProcesses]; for (int i = 0; i < totalOfProcesses; i++) { tasks[i] = context.CallSubOrchestratorAsync <string>("SubOrchestratorExample", $"Activity {i}"); } await Task.WhenAll(tasks); //var list = new List<String>(); return(tasks.Select(t => t.Result).ToList()); }
public static async Task CreateCoreResources( [OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log) { CreationParameters creationParams = context.GetInput <CreationParameters>(); if (!context.IsReplaying) { log.LogWarning("ORC - Creating Core Resources in: {resourceGroupName}", creationParams.ResourceGroupName); } //await context.CallActivityWithRetryAsync( // nameof(ResourceCreationActivities.CreateAppServicePlan), // new RetryOptions(TimeSpan.FromMinutes(1), maxNumberOfAttempts: 3) // { // BackoffCoefficient = 1.0, // Handle = ex => // { // if (ex is CloudException) // { // log.LogError(ex, "failed to create app service plan..."); // return true; // } // // don't bother retrying on any other exceptions // return false; // }, // RetryTimeout = TimeSpan.FromMinutes(1) // }, // creationParams); var storageRequest = CreateStorageAccountRequest.FromCreationParams(creationParams); storageRequest.StorageAccountName = ResourceCreationActivities.GenerateStorageAccountName(creationParams, "logs"); var t1 = context.CallSubOrchestratorAsync(nameof(CreateCustomerAppServicePlan), creationParams); var t2 = context.CallActivityAsync <CreateStorageAccountResult>(nameof(ResourceCreationActivities.CreateStorageAccount), storageRequest); await Task.WhenAll(t1, t2); if (!context.IsReplaying) { log.LogWarning($"ORC - Created Storage Account Name: {t2.Result.StorageAccountName} - Primary Key: {t2.Result.PrimaryKey.KeyName}, {t2.Result.PrimaryKey.Value}"); log.LogWarning($"ORC - Created Core Resources in: {creationParams.ResourceGroupName}"); } }
public async Task SearchOrchestrationAsync( [OrchestrationTrigger] DurableOrchestrationContextBase context, [Table(Constants.WishTableName)] CloudTable wishTable, [Pushover] IAsyncCollector <PushoverNotification> notifications) { var model = context.GetInput <SearchContext>(); var results = new List <WishResult>(); foreach (var provider in model.Providers) { var providerResults = await context.CallSubOrchestratorAsync <IEnumerable <WishResult> >(SubOrchestrator, new SearchProviderContext { Provider = provider, Wishes = model.Wishes }); results.AddRange(providerResults); } if (results.Any()) { var addResultsCmd = new AddWishResultsCommand(results); await wishTable.ExecuteAsync(addResultsCmd); var wishNames = results.GroupBy(r => r.WishName) .Select(r => r.Key) .Distinct(); await notifications.AddAsync(new PushoverNotification { Title = "NZB Wishlist", Message = $"Found new results for {string.Join(", ", wishNames)}" }); } var updateWishesCmd = new UpdateLastSearchDateCommand(model.Wishes); await wishTable.ExecuteAsync(updateWishesCmd); }
public static async Task <Response> Run1( [OrchestrationTrigger] DurableOrchestrationContextBase context) { var output = new Dictionary <string, int>(); double volume = 0.0; output.Add(Environment.MachineName, Environment.ProcessorCount); var depth = context.GetInput <int>(); if (depth > 0) { var tasks = new List <Task <Response> >(); for (int i = 0; i < 10; i++) { tasks.Add(context.CallActivityAsync <Response>("DFLoadTestActivity", (depth - 1).ToString())); tasks.Add(context.CallSubOrchestratorAsync <Response>("DFLoadTestOrchestration", (depth - 1).ToString())); } await Task.WhenAll(tasks); foreach (var t in tasks) { volume += t.Result.Volume; foreach (var kvp in t.Result.Hosts) { output[kvp.Key] = kvp.Value; } } } return(new Response() { Volume = volume, Hosts = output, Elapsed = 0.0, // filled in later }); }
public async Task <IActionResult> LoadWaterAllocationDataOrchestration([OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log) { var runId = context.GetInput <string>(); var parallelTasks = new List <Task <StatusHelper> > { context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadOrganizations, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadSites, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadWaterSources, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadMethods, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadRegulatoryOverlays, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadReportingUnits, runId) , context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadVariables, runId) }; var parallelResults = await Task.WhenAll(parallelTasks); foreach (var result in parallelResults) { log.LogInformation(JsonConvert.SerializeObject(result)); } if (parallelResults.Any(a => !a.Status)) { throw new Exception("Failure Loading Initial Data"); } var results = new List <StatusHelper> { await context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadAggregatedAmounts, runId) , await context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadWaterAllocations, runId) , await context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadSiteSpecificAmounts, runId) , await context.CallSubOrchestratorAsync <StatusHelper>(FunctionNames.LoadRegulatoryReportingUnits, runId) }; foreach (var result in results) { log.LogInformation(JsonConvert.SerializeObject(result)); } if (results.Any(a => !a.Status)) { throw new Exception("Failure Loading Fact Data"); } return(new OkObjectResult(new { status = "success" })); }
public static async Task <List <CartData> > Run([OrchestrationTrigger] DurableOrchestrationContextBase context, TraceWriter log) { var cart = context.GetInput <List <CartData> >() ?? new List <CartData>(); var addItemTask = context.WaitForExternalEvent <CartData>(CartEvents.AddItem); var removeItemTask = context.WaitForExternalEvent <CartData>(CartEvents.RemoveItem); var isCompletedTask = context.WaitForExternalEvent <bool>(CartEvents.IsCompleted); var setCartReminder = context.WaitForExternalEvent <CartReminderData>(CartEvents.SetReminder); // Wait for any external event var resultingEvent = await Task.WhenAny(addItemTask, removeItemTask, isCompletedTask, setCartReminder); // Add item to cart if (resultingEvent == addItemTask) { cart.Add(addItemTask.Result); context.SetCustomStatus("readynow"); if (!context.IsReplaying) { log.Info($"Added {addItemTask.Result.ItemName} to the Shopping Cart."); } } // Remove Item from cart else if (resultingEvent == removeItemTask) { cart.Remove(cart.Find(x => x.ItemId == removeItemTask.Result.ItemId)); context.SetCustomStatus("readynow"); if (!context.IsReplaying) { log.Info($"Removed {removeItemTask.Result.ItemName} from the Shopping Cart."); } } // Add reminder for cart (used to notify user of waiting cart with items) else if (resultingEvent == setCartReminder) { var provisionTask = context.CallSubOrchestratorAsync("SetCartNotificationTimer", setCartReminder.Result); if (!context.IsReplaying) { log.Info($"Added timer ({setCartReminder.Result.RemindInMinutes} minutes) for Shopping Cart."); } } // Complete cart or stay running ? if (resultingEvent == isCompletedTask && isCompletedTask.Result) { if (!context.IsReplaying) { log.Info("Completed the Shopping Cart."); } } else { context.ContinueAsNew(cart); // the magic line if (!context.IsReplaying) { log.Info($"cartList Count: {cart.Count}"); } } return(await Task.FromResult(cart)); }
public static Task DurableFunctionWithSubOrchestration( [OrchestrationTrigger] DurableOrchestrationContextBase context) { return(context.CallSubOrchestratorAsync(nameof(SubOrchestration), null)); }
public static async Task <List <string> > E1_HelloSequenceWithSuborchestrator( [OrchestrationTrigger] DurableOrchestrationContextBase context) { Task <dynamic> cancellationTask = context.WaitForExternalEvent <dynamic>("CancelSequence"); var outputs = new List <string>(); //context.GetInput(); await context.CallActivityAsync("SignalRAddUserToGroup", null); // STEP 1 var step1 = context.CallSubOrchestratorAsync <SubOrchestratorExampleOutput>("SubOrchestratorExample", new SubOrchestratorExampleModel { Input = "Seattle", Progress = 20 }); Task winner = await Task.WhenAny(cancellationTask, step1); if (winner == cancellationTask) { var x = cancellationTask.Result; outputs.Add("Canceled during step 1"); await context.CallActivityAsync <string>("SendSignalRMessageActivity", new SignalRDto { id = context.InstanceId, message = $"Result: {String.Join(" ", outputs)}", progress = 100 }); return(outputs); } outputs.Add(step1.Result.Message); // STEP 2 var step2 = context.CallSubOrchestratorAsync <SubOrchestratorExampleOutput>("SubOrchestratorExample", new SubOrchestratorExampleModel { Input = "Utrecht", Progress = 40 }); winner = await Task.WhenAny(cancellationTask, step2); if (winner == cancellationTask) { outputs.Add("Canceled during step 2"); await context.CallActivityAsync <string>("SendSignalRMessageActivity", new SignalRDto { id = context.InstanceId, message = $"Result: {String.Join(" ", outputs)}", progress = 100 }); return(outputs); } outputs.Add(step2.Result.Message); // STEP 3 var step3 = context.CallSubOrchestratorAsync <SubOrchestratorExampleOutput>("SubOrchestratorExample", new SubOrchestratorExampleModel { Input = "Future Tech", Progress = 60 }); winner = await Task.WhenAny(cancellationTask, step3); if (winner == cancellationTask) { outputs.Add("Canceled during step 3"); await context.CallActivityAsync <string>("SendSignalRMessageActivity", new SignalRDto { id = context.InstanceId, message = $"Result: {String.Join(" ", outputs)}", progress = 100 }); return(outputs); } outputs.Add(step3.Result.Message); await context.CallActivityAsync <string>("SendSignalRMessageActivity", new SignalRDto { id = context.InstanceId, message = $"Result: {String.Join(" ", outputs)}", progress = 100 }); return(outputs); }