public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var data = await req.Content.ReadAsAsync <IList <BulkImportJob> >(); // Function input comes from the request content. string instanceId = await starter.StartNewAsync("MonitorBulkImport", data); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter?.CreateCheckStatusResponse(req, instanceId)); }
public async Task <IActionResult> ConfirmCommuntyHttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, HttpVerbs.POST, Route = "Community")] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var communityValidateRequest = await req.GetJsonBodyWithValidator(new CommunityValidator(communityService)); if (!communityValidateRequest.IsValid) { log.LogError($"Invalid form data"); return(communityValidateRequest.ToBadRequest()); } string instanceId = await starter.StartNewAsync(ConfirmationTask.ConfirmOrchestratorCommunity, null, communityValidateRequest.Value); return(starter.CreateCheckStatusResponse(req, instanceId)); }
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 requestBody = await req.Content.ReadAsStringAsync().ConfigureAwait(false); dynamic data = JsonConvert.DeserializeObject(requestBody); string name = data?.name ?? "Unknown"; string instanceId = await starter.StartNewAsync <string>("Function1", name); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var cart = JsonConvert.DeserializeObject <CartDto>(requestBody); if (cart == null || cart.Name == null || cart.Address == null || cart.Lines == null || cart.Lines.Count == 0) { return(new BadRequestObjectResult("Please pass a name on the query string or in the request body")); } var orchestrationId = await starter.StartNewAsync("O_ProcessCheckout", cart); return(starter.CreateCheckStatusResponse(req, orchestrationId)); }
public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var loginData = await req.Content.ReadAsAsync <TeslaLogin>(); var entityId = new EntityId(nameof(LastChargeState), loginData.Email); //await entityClient.SignalEntityAsync(entityId, "Set", ChargingStatus.Other); string instanceId = await starter.StartNewAsync("OrchestrateCheck", new OrchestrationData() { LoginData = loginData, EntityId = entityId }); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> TriggerMethod([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] TriggerRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var instanceId = Guid.NewGuid().ToString(); try { instanceId = await starter.StartNewAsync <(string, string)> (nameof(OrchestrationFunction.Orchestrate), instanceId, ("input1", "input2")); } catch (Exception e) { log.LogError("something went wrong in trigger"); throw e; } return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> Run( HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, string functionName, ILogger log) { // Function input comes from the request content. object eventData = await req.Content.ReadAsAsync <object>(); var instanceId = await starter.StartNewAsync(functionName, eventData); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); var res = starter.CreateCheckStatusResponse(req, instanceId); res.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromSeconds(10)); return(res); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage request, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var input = await request.GetJsonBody <NotifyTicket, NotifyTicketValidator>(); return(await input.Match( valid => StartNotifyTicket(valid), invalid => Task.FromResult(request.BadRequest(invalid)))); async Task <HttpResponseMessage> StartNotifyTicket(NotifyTicket ticket) { var instanceId = await starter.StartNewAsync(nameof(WatcherOrchestration.ShareListedTickets), new[] { ticket.Id }); return(starter.CreateCheckStatusResponse(request, instanceId)); } }
public static async Task <IActionResult> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); string fileName = req.Query["fileName"]; dynamic data = JsonConvert.DeserializeObject(requestBody); fileName = fileName ?? data?.fileName ?? "Client Sample Data file.xlsx"; var file = await RecoverFile(fileName); var instanceId = await starter.StartNewAsync("Durable", null, file); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <IActionResult> GetTargetFunctionAppAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient client, Microsoft.Extensions.Logging.ILogger log) { var body = await req.ReadAsStringAsync(); var appContext = JsonConvert.DeserializeObject <AppContext>(body); if (appContext == null || appContext.Version == null) { return(new BadRequestObjectResult("Malformed Json format or missing Version. Check the value")); } string instanceId = await client.StartNewAsync("CreateOrUpdateFunctionAppOrchestrator", appContext); return(client.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { // var currentActivity = new Activity("New Client"); // currentActivity.GenerateW3CContext(); //currentActivity.Start(); // Function input comes from the request content. string instanceId = await starter.StartNewAsync("Function1", null); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); //currentActivity.Stop(); return(starter.CreateCheckStatusResponse(req, instanceId)); // TraceContextFactory f = null; //works // AzureStorageOrchestrationService s = null; }
public async Task <IActionResult> TaskSchedulerRunner( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [DurableClient] IDurableOrchestrationClient client, ILogger log) { if (client is null) { throw new ArgumentNullException(nameof(client)); } var taskItem = await GetTaskItem(req); if (taskItem == null) { return(new OkObjectResult($"TaskItem argument not valid")); } var orchestratorInstanceId = _service.TaskId(taskItem); if (string.IsNullOrWhiteSpace(orchestratorInstanceId.ToString())) { return(new OkObjectResult("orchestratorId missing")); } DurableOrchestrationStatus status = await client.GetStatusAsync(orchestratorInstanceId); if (status != null && status.RuntimeStatus == OrchestrationRuntimeStatus.Running) { return(new OkObjectResult(status)); } if (status != null && status.RuntimeStatus == OrchestrationRuntimeStatus.Pending) { await client.TerminateAsync(orchestratorInstanceId, "New scheduler time"); } string instanceId = await client.StartNewAsync <TaskItem>(nameof(StartOrchestratorScheduler), orchestratorInstanceId, taskItem); var result = client.CreateCheckStatusResponse(req, instanceId); return(result); }
public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { // Function input comes from the request content. log.LogInformation($"StartNewAsync method called!!!"); string instanceId = await starter.StartNewAsync("Function1", null); logger.LogInformation($"Started orchestration with ID = '{instanceId}'."); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); for (int x = 0; x < 1000; x++) { System.Threading.Thread.SpinWait(100000); } return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [OrchestrationClient] IDurableOrchestrationClient starter, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string instanceId = null; var orderDto = await ReadOrderFromRequestAsync(req); if (orderDto != null) { var order = orderDto.ToOrder(); instanceId = await starter.StartNewAsync(FunctionNames.OrderWorkflowFunction, order.Id, order); return(starter.CreateCheckStatusResponse(req, instanceId)); } return(new BadRequestResult()); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var request = JsonConvert.DeserializeObject <AddCertificateRequest>(await req.Content.ReadAsStringAsync()); if (request?.Hostnames == null || request.Hostnames.Length == 0) { return(req.CreateErrorResponse(HttpStatusCode.BadRequest, $"{nameof(request.Hostnames)} is empty.")); } // Function input comes from the request content. string instanceId = await starter.StartNewAsync("AddMultipleCertificatesFunctions", request.Hostnames); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId, true)); }
public static async Task <HttpResponseMessage> Start( [HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "StartSubOrchestrationFanOutFanIn")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { if (!int.TryParse(req.GetQueryNameValuePairs().First(q => q.Key == "count").Value, out int count) || count < 1) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = "A 'count' query string parameter is required and it must contain a positive number." }); } string instanceId = await starter.StartNewAsync <object>("FanOutFanInOrchestration", count); log.LogWarning("Started FanOutFanInOrchestration orchestration with ID = '" + instanceId + "'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <IActionResult> ProcessVideoStarter( [HttpTrigger(AuthorizationLevel.Function, "get", "post", 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 a video location on the query string")); } log.LogInformation($"Attempting to start video processing for {video}."); var instanceId = await starter.StartNewAsync(OrchestratorNames.ProcessVideo, video); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { // Function input comes from the request content. var jsonInput = await req.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonInput)) { jsonInput = "{}"; } string instanceId = await starter.StartNewAsync("GenerateFiltersOrch", null, jsonInput); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { await using var stream = await req.Content.ReadAsStreamAsync(); var(containerName, blobName, sasUrl) = await _blobStorageClient.Upload(stream); string instanceId = await starter.StartNewAsync(OrchestratorName, new OrchestratorInput { SasUrl = sasUrl, ContainerName = containerName, BlobName = blobName }); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var requestId = req.Headers.GetValues("Request-Id").FirstOrDefault(); if (string.IsNullOrEmpty(requestId)) { log.LogInformation("Request-Id can not be empty."); return(req.CreateErrorResponse(HttpStatusCode.BadRequest, "Request-Id header is required.")); } string instanceId = await starter.StartNewAsync("Orchestration_W3C", null); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "orchestrators/{functionName}/wait")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, string functionName, ILogger log) { //Creates a guid before starting the orchestration and reads input from user string transactionId = Guid.NewGuid().ToString(); DocToP360Request eventData = await req.Content.ReadAsAsync <DocToP360Request>(); string instanceId = await starter.StartNewAsync(functionName, transactionId, (eventData, transactionId)); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); //Creates a JSON-file that includes all the input parameters for the orchestration. /* * System.IO.File.WriteAllText(@"FILEPATH", JsonConvert.SerializeObject(new DocToP360Request() * { * * parameter = new Parameter() * { * PrivateAddress = new Privateaddress() * { * * }, * ArchiveCodes = new List<Archivecode> { new Archivecode(){ * } }, * Files = new List<Models.VTFK.File>() * { * new Models.VTFK.File(){} * } * * * } * }, Formatting.Indented));*/ var res = starter.CreateCheckStatusResponse(req, transactionId); return(res); }
public async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "orchestrators/{orchestratorName}/{instanceId}")] HttpRequestMessage req, [DurableClient(TaskHub = "%PostCallCleanupDurableTaskHubName%")] IDurableOrchestrationClient starter, string orchestratorName, string instanceId, ILogger log) { try { // Check if an instance with the specified ID already exists. var instance = await starter.GetStatusAsync(instanceId); if (instance == null || !(instance.RuntimeStatus == OrchestrationRuntimeStatus.Pending || instance.RuntimeStatus == OrchestrationRuntimeStatus.Running || instance.RuntimeStatus == OrchestrationRuntimeStatus.ContinuedAsNew)) { // An instance with the specified ID doesn't exist, create one. await starter.StartNewAsync(orchestratorName, instanceId); log.LogInformation($"Started orchestration '{orchestratorName}' with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); } else { log.LogInformation($"Orchestration '{orchestratorName}' with ID = '{instanceId}' already exists."); // An instance with the specified ID exists, don't create one. return(req.CreateErrorResponse( HttpStatusCode.Conflict, $"An instance with ID '{instanceId}' already exists.")); } } catch (Exception ex) { log.LogError(ex, "PostCallCleanupEternalOrchestrator_HttpStart: An error occurred while starting orchestrator"); return(req.CreateErrorResponse( HttpStatusCode.InternalServerError, $"{ex.Message}")); } }
private static async Task <HttpResponseMessage> SendEventToOrderAsync(HttpRequestMessage req, IDurableOrchestrationClient starter, string orderEvent, ILogger log) { var jsonContent = await req.Content.ReadAsStringAsync(); OrderEventDto orderEventDto = JsonConvert.DeserializeObject <OrderEventDto>(jsonContent); if (orderEventDto != null && !string.IsNullOrWhiteSpace(orderEventDto.OrderId)) { await starter.RaiseEventAsync(orderEventDto.OrderId, orderEvent, null); return(starter.CreateCheckStatusResponse(req, orderEventDto.OrderId)); } return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest) { ReasonPhrase = "Order not valid" }); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [OrchestrationClient] IDurableOrchestrationClient starter, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <Order>(requestBody); if (data is Order order) { string orchestrationId = await starter.StartNewAsync("OrderOrchestrator", order); return(starter.CreateCheckStatusResponse(req, orchestrationId)); } return(new BadRequestResult()); }
public async Task <HttpResponseMessage> HttpStart_With_W3C( [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var traceparent = req.Headers.GetValues("traceparent").FirstOrDefault(); // HttpCorrelationProtocol uses Request-Id var currentActivity = Activity.Current; if (string.IsNullOrEmpty(traceparent)) { log.LogInformation("Traceparent can not be empty."); return(req.CreateErrorResponse(HttpStatusCode.BadRequest, "Traceparent header is required.")); } string instanceId = await starter.StartNewAsync(nameof(this.Orchestration_W3C), null); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req, [DurableClient] IDurableEntityClient client, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { var updatedState = req.RequestUri.ParseQueryString().Get("state"); log.LogInformation($"Received request to update status to {updatedState}."); var currentState = await client.ReadEntityStateAsync <string>(EntityId); if (currentState.EntityExists && currentState.EntityState == updatedState) { log.LogInformation($"Door status is already {currentState.EntityState}. Will not start a new orchestrator instance."); HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent($"Door status is already {currentState.EntityState}.") }; return(httpResponseMessage); } // Update the entity. await client.SignalEntityAsync(EntityId, "update", updatedState); log.LogInformation($"Updated status to {updatedState}."); if (updatedState.ToLowerInvariant() == "closed") { HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.NoContent); return(httpResponseMessage); } var delay = Environment.GetEnvironmentVariable("TimerDelayMinutes"); var delayTimeSpan = TimeSpan.FromMinutes(Convert.ToInt32(delay)); // Function input comes from the request content. string instanceId = await starter.StartNewAsync <TimeSpan>("Main", null, delayTimeSpan); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); }
private async Task <HttpResponseMessage> HandleStartOrchestratorRequestAsync( HttpRequestMessage request, string functionName, string instanceId) { try { IDurableOrchestrationClient client = this.GetClient(request); object input = null; if (request.Content != null) { using (Stream s = await request.Content.ReadAsStreamAsync()) using (StreamReader sr = new StreamReader(s)) using (JsonReader reader = new JsonTextReader(sr)) { JsonSerializer serializer = JsonSerializer.Create(MessagePayloadDataConverter.MessageSettings); input = serializer.Deserialize <object>(reader); } } string id = await client.StartNewAsync(functionName, instanceId, input); TimeSpan?timeout = GetTimeSpan(request, "timeout"); TimeSpan?pollingInterval = GetTimeSpan(request, "pollingInterval"); if (timeout.HasValue && pollingInterval.HasValue) { return(await client.WaitForCompletionOrCreateCheckStatusResponseAsync(request, id, timeout.Value, pollingInterval.Value)); } else { return(client.CreateCheckStatusResponse(request, id)); } } catch (JsonReaderException e) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid JSON content", e)); } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "scenario")] HttpRequest req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { try { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var scenario = JsonConvert.DeserializeObject <ScenarioRequest>(requestBody); var orchestratorId = await starter.StartNewAsync("ScenarioOrchestrator", scenario); log.LogInformation($"Started scenario with ID = '{orchestratorId}'."); return(starter.CreateCheckStatusResponse(req, orchestratorId)); } catch (Exception e) { log.LogError(e.Message); return(new ExceptionResult(e, true)); } }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { string lastTweetId = req.RequestUri.ParseQueryString()["lastTweetId"]; if (lastTweetId == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Please pass lastTweetId in the query string."), }); } log.LogDebug($"Starting orchestration for lastTweetId: {lastTweetId}"); // Function input comes from the request content. string orchestrationId = await starter.StartNewAsync <string>("O_MainOrchestrator", lastTweetId); return(starter.CreateCheckStatusResponse(req, orchestrationId)); }
public static async Task <HttpResponseMessage> HttpStart( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req, [DurableClient] IDurableOrchestrationClient starter, ILogger log) { try { // INPUT : {"PartitionKey":["input-040120201213","input-050120201213","input-060120201213"]} var data = await req.Content.ReadAsAsync <PartitionKeyGenerator>(); // Function input comes from the request content. string instanceId = await starter.StartNewAsync("Orchestration_ScheduleExam", data); log.LogInformation($"Started orchestration with ID = '{instanceId}'."); return(starter.CreateCheckStatusResponse(req, instanceId)); } catch (System.Exception ex) { throw ex; } }