public static async Task <IActionResult> HttpTrigger( [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpTriggerArgs args, [OrchestrationClient] IDurableOrchestrationClient durableOrchestrationClient, ILogger log) { // 'orchestrationId = DeviceId' > tricky stuff, make sure the orchestrationId is deterministic but also unique and has now weird characters var orchestrationId = args.DeviceId; var status = await durableOrchestrationClient.GetStatusAsync(orchestrationId); // Maybe do this from within the Orchestrator var entity = new EntityId(nameof(DeviceEntity), args.DeviceId); await durableOrchestrationClient.SignalEntityAsync(entity, "UpdateLastCommunicationDateTime"); switch (status?.RuntimeStatus) { case OrchestrationRuntimeStatus.Running: case OrchestrationRuntimeStatus.Pending: case OrchestrationRuntimeStatus.ContinuedAsNew: await durableOrchestrationClient.RaiseEventAsync(orchestrationId, "MessageReceived", null); break; default: await durableOrchestrationClient.StartNewAsync(nameof(WaitingOrchestrator), orchestrationId, new OrchestratorArgs { DeviceId = args.DeviceId }); break; } log.LogInformation("Started orchestration with ID = '{orchestrationId}'.", orchestrationId); var response = durableOrchestrationClient.CreateHttpManagementPayload(orchestrationId); return(new OkObjectResult(response)); }
public async Task <IActionResult> AMS_EncodingStart( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "AMS/StartEncode")] [RequestBodyType(typeof(DFJobInputDTO), "CreateLesson request")] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, [SwaggerIgnore] ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var reqBody = JsonConvert.DeserializeObject <DFJobInputDTO>(requestBody); var assetAMS = await _amsService.GetAssetAMS(reqBody.AssetId); var configAsset = new ConfigAssetDTO() { AssetID = reqBody.AssetId, InputName = string.Format(_configAsset.InputName, assetAMS.ContentAddress), OutputName = string.Format(_configAsset.OutputName, assetAMS.ContentAddress), JobName = string.Format(_configAsset.JobName, assetAMS.ContentAddress), LocatorName = string.Format(_configAsset.LocatorName, assetAMS.ContentAddress) }; var inputConfigAsset = JsonConvert.SerializeObject(configAsset); var instanceId = await starter.StartNewAsync("AMS_EncodeOrchestrator", input : inputConfigAsset); var payload = starter.CreateHttpManagementPayload(instanceId); return(new OkObjectResult(new { instanceId, terminatePostUri = payload.TerminatePostUri, sendEventPostUri = payload.SendEventPostUri, purgeHistoryDeleteUri = payload.PurgeHistoryDeleteUri, })); }
public async Task Run( [ServiceBusTrigger(PrepareToSendQueue.QueueName, Connection = PrepareToSendQueue.ServiceBusConnectionConfigurationKey)] string myQueueItem, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { // Get Notification Data var queueMessageContent = JsonConvert.DeserializeObject <PrepareToSendQueueMessageContent>(myQueueItem); var notificationId = queueMessageContent.NotificationId; var sentNotificationDataEntity = await this.notificationDataRepository.GetAsync( partitionKey : NotificationDataTableNames.SentNotificationsPartition, rowKey : notificationId); if (sentNotificationDataEntity == null) { log.LogError($"Notification entity not found. Notification Id: {notificationId}"); return; } // Start PrepareToSendOrchestrator function. string instanceId = await starter.StartNewAsync( FunctionNames.PrepareToSendOrchestrator, sentNotificationDataEntity); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); var httpManagementPayload = starter.CreateHttpManagementPayload(instanceId); sentNotificationDataEntity.FunctionInstancePayload = JsonConvert.SerializeObject(httpManagementPayload); await this.notificationDataRepository.InsertOrMergeAsync(sentNotificationDataEntity); }
public static async Task <IActionResult> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "orchestrators/{orchestratorName}")] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, string orchestratorName, ILogger log) { var input = default(RequestModel); using (var reader = new StreamReader(req.Body)) { var serialised = await reader.ReadToEndAsync(); log.LogInformation(serialised); input = JsonConvert.DeserializeObject <RequestModel>(serialised); } // Function input comes from the request content. var instanceId = await starter.StartNewAsync <RequestModel>(orchestratorName, instanceId : null, input : input); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); var mgmt = starter.CreateHttpManagementPayload(instanceId); return(new OkObjectResult(mgmt)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { log.LogInformation(">>>>> C# HTTP trigger function processed a request."); //string name = req.Query["name"]; //string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); //dynamic data = JsonConvert.DeserializeObject(requestBody); //name = name ?? data?.name; //string responseMessage = string.IsNullOrEmpty(name) // ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." // : $"Hello, {name}. This HTTP triggered function executed successfully."; string instanceId = await starter.StartNewAsync("O_ProcessSendVideo", null); var payload = starter.CreateHttpManagementPayload(instanceId); log.LogInformation($">>>>> Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public void LogManagmentUrls(IDurableOrchestrationClient starter, string instanceId) { var mgmtUrls = starter.CreateHttpManagementPayload(instanceId); var mgmtString = JsonConvert.SerializeObject(mgmtUrls); Log.LogInformation(mgmtString); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "register/")] HttpRequest req, ILogger logger, [DurableClient] IDurableOrchestrationClient starter ) { this.log = logger; log.LogInformation("Received registration start request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = UserRegistration.FromJson(requestBody); telemetry.TrackEvent( "RegistrationStarted", new Dictionary <string, string>() { { "UserName", data.UserName }, { "UserEmail", data.UserEmail }, { "UserPhone", data.UserPhone } } ); var instanceId = Guid.NewGuid().ToString(); new RegistrationEntity( "RegisterOrchestrator", instanceId, data ).Save(); await starter.StartNewAsync <string>( "RegisterOrchestrator", instanceId, data.ToString() ); var managementPayload = starter.CreateHttpManagementPayload(instanceId); log.LogInformation("Saving entity"); new OrchestrationEntity( "RegisterOrchestrator", DateTime.Now, managementPayload ).Save(); return(new ContentResult() { Content = JsonSerializer.Serialize(managementPayload), ContentType = "application/json", StatusCode = StatusCodes.Status202Accepted }); }
public static async Task <IActionResult> HttpTrigger( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpTriggerArgs args, [DurableClient] IDurableOrchestrationClient durableOrchestrationClient, ILogger log) { var orchestrationId = await durableOrchestrationClient.StartNewAsync(nameof(Orchestration), args); log.LogInformation("Started orchestration with ID = '{orchestrationId}'.", orchestrationId); var response = durableOrchestrationClient.CreateHttpManagementPayload(orchestrationId); return(new OkObjectResult(response)); }
public static async Task <IActionResult> Run( [DurableClient] IDurableOrchestrationClient orchestrationClient, [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("OrchestrationClient called."); string instanceId = await orchestrationClient.StartNewAsync(Orchestrator.FunctionName); var payload = orchestrationClient.CreateHttpManagementPayload(instanceId); return(new AcceptedResult(payload.StatusQueryGetUri, payload)); }
public static async Task <IActionResult> StartPeriodicTask( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient client, ILogger log) { var instanceId = "PeriodicTask"; // use a fixed id, making it easier for us to terminate await client.StartNewAsync("O_PeriodicTask", instanceId, 0); var payload = client.CreateHttpManagementPayload(instanceId); return(new OkObjectResult(payload)); }
public static async Task<HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req, [DurableClient]IDurableOrchestrationClient starter, ILogger log) { // Function input comes from the request content. string instanceId = await starter.StartNewAsync("DurableFunctionsOrchestrationCSharp", null); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); //var status=starter.GetStatusAsync(instanceId); // return req.CreateResponse(status.Result); // return starter.CreateCheckStatusResponse(req, instanceId); return req.CreateResponse( starter.CreateHttpManagementPayload(instanceId).StatusQueryGetUri); }
public async Task <object> OrchestratorAsync( [HttpTrigger("get", "post", "delete")] HttpRequest request, [DurableClient] IDurableOrchestrationClient durableOrchestrationClient) { var method = request.Method.ToLower(); if (method == "get") { return(await durableOrchestrationClient.GetInstancesAsync()); } if (method == "delete") { await Task.WhenAll( from i in await durableOrchestrationClient.GetInstancesAsync() where i.RuntimeStatus == OrchestrationRuntimeStatus.Running select durableOrchestrationClient.TerminateAsync(i.InstanceId, "terminate-all") ); return(await Task.WhenAll( from i in await durableOrchestrationClient.GetInstancesAsync() where i.RuntimeStatus != OrchestrationRuntimeStatus.Running select durableOrchestrationClient.PurgeInstanceHistoryAsync(i.InstanceId) )); } var body = await request.Body.ReadAsync(); var functionContext = body.FromJson <FunctionContext>() ?? new FunctionContext(); functionContext.BaseUrl = new Uri(request.GetDisplayUrl()).GetLeftPart(UriPartial.Authority); functionContext.MethodSpecification = functionContext.MethodSpecification ?? request.Query["$method"]; functionContext.Await = functionContext.Await || ((string)request.Query["$await"]).ChangeType <bool>(); functionContext.CallbackUrl = functionContext.CallbackUrl ?? request.Query["$callbackUrl"]; functionContext.Arguments = functionContext.Arguments ?? JToken.FromObject(( from q in request.Query where !q.Key.StartsWith("$") select(q.Key, Value: q.Value.FirstOrDefault() as object) ).ToDictionary()); if (functionContext.Await) { return(await functionContext.InvokeAsync(this.componentContext)); } var instanceId = await durableOrchestrationClient.StartNewAsync("orchestration", functionContext); return(durableOrchestrationClient.CreateHttpManagementPayload(instanceId) as object); }
public static async Task <IActionResult> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "step-7")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var requestData = await req.Content.ReadAsAsync <Step7_RequestData>(); var instanceId = starter.StartNewAsync("Step7_Orchestrator", requestData).Result; log.LogWarning($"Started orchestration with ID = '{instanceId}'."); var orchestratorId = starter.CreateHttpManagementPayload(instanceId); return(new OkObjectResult(orchestratorId)); }
public static async Task Run([CosmosDBTrigger( databaseName: "inventory", collectionName: "shipments", ConnectionStringSetting = "CosmosDBConnection", LeaseCollectionName = "leases", CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document> input, ILogger log, [DurableClient] IDurableOrchestrationClient starter) { if (input == null) { log.LogWarning("Client has received no documents"); return; } foreach (var item in input) { try { //deserializes payload to object and "transform" it string stringifiedItem = item.ToString(); InputShipmentEvent inputItem = InputShipmentEvent.Deserialize(stringifiedItem); if (inputItem == null) { throw new InvalidOperationException("InputOnHandEvent not deserialized from payload string"); } log.LogInformation(inputItem.id); //re-serializes payload and sends it to orchestrator var inventoryEvents = InputShipmentEvent.ResolveToInventoryEvents(inputItem); foreach (var invEvent in inventoryEvents) { string instanceId = await starter.StartNewAsync("StoreOrchestrator", null, invEvent).ConfigureAwait(false); var mgmtUrls = starter.CreateHttpManagementPayload(instanceId); log.LogInformation(inputItem.id, mgmtUrls.ToString()); } } catch (Exception e) { log.LogError(e.Message); } } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { // parse query parameter string video = req.GetQueryParameterDictionary()["video"]; if (video == null) { return(new BadRequestObjectResult( "Please pass the video location the query string")); } log.LogInformation($"About to start orchestration for {video}"); var orchestrationId = await starter.StartNewAsync("O_ProcessVideo", null, video); var payload = starter.CreateHttpManagementPayload(orchestrationId); return(new OkObjectResult(payload)); }