public static async Task Run([EventGridTrigger] JObject eventGridEvent, TraceWriter log) { try { var(action, fileName, isBuilding) = EventGridHelper.GetEventInfo(eventGridEvent); log.Info($"Detectado el blob {fileName}, al tajo..."); if (action.Equals("Microsoft.Storage.BlobCreated")) { log.Info($"Evento {action}, llega la magia"); if (isBuilding) { log.Info($"{functionName} Es una carga de edificios"); await new ProcessBuildings().ProccessByFileAsync(fileName, functionName, log); } else { log.Info($"{functionName} Es una carga de domicilio"); await new ProcessHomes().ProccessByFileAsync(fileName, functionName, log); } } else { log.Info($"Evento {action}, no hacemos nada"); } } catch (System.Exception ex) { log.Info($"ERROR {ex.Message}"); } }
public static async Task Run([EventGridTrigger] JObject eventGridEvent, TraceWriter log) { var(action, fileName) = EventGridHelper.GetEventInfo(eventGridEvent); try { LoggerHelper.WriteTrace(functionName, $"Procesando el blob {fileName} | a las {DateTime.UtcNow.ToString("dd/MM/yyyy HH-mm-ss")}", log, TraceLevel.Info, _telemetry); if (action.Equals("Microsoft.Storage.BlobCreated")) { await new HotelsHelper().ProccessByFileAsync(fileName, functionName, log, _telemetry); } else { LoggerHelper.WriteTrace(functionName, $"Evento {action} | a verlas pasar {DateTime.UtcNow.ToString("dd/MM/yyyy HH-mm-ss")}", log, TraceLevel.Info, _telemetry); } } catch (Exception ex) { LoggerHelper.WriteTrace(functionName, $"Se ha producido un error en {fileName} | {action} a las {DateTime.UtcNow.ToString("dd/MM/yyyy HH-mm-ss")}. Error: {ex} , {ex.InnerException} ", log, TraceLevel.Error, _telemetry); throw; } log.Info(eventGridEvent.ToString(Formatting.Indented)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [CosmosDB("chastelDatabase", "clientBookingRequests", Id = "Id", CreateIfNotExists = true, PartitionKey = "/DispatchSystemId", ConnectionStringSetting = "ChastelDBConnectionString")] IAsyncCollector <PaxRequestsClientBookingModel> documents, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); // parsing client booking data from request's body var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var clientBookingData = JsonConvert.DeserializeObject <PaxRequestsClientBookingModel>(requestBody); // 1. store request documents.AddAsync(clientBookingData).GetAwaiter(); // 2. post to Azure Event Grid for next handler EventGridHelper.RaiseEventToGridAsync(topicEndpoint, sasKey, nameof(PaxRequestsClientBookingFunction), nameof(ChastelEventTopic.UnassignedClientBooking), nameof(ChastelEventType.HttpFunctionEvent), clientBookingData).GetAwaiter(); // finally return return(clientBookingData != null ? (ActionResult) new OkObjectResult($"Hello, booking {clientBookingData.DispatchSystemId}-{clientBookingData.DispatchBookingId}") : new BadRequestObjectResult("Please pass a name on the query string or in the request body")); }