public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [CosmosDB(
                 Constants.DATABASE_NAME,
                 Constants.ROUTES_COLLECTION,
                 ConnectionStringSetting = Constants.DATABASE_CONNECTION_STRING_SETTING,
                 CreateIfNotExists = true)] IAsyncCollector <Route> routes,
            [CosmosDB(
                 Constants.DATABASE_NAME,
                 Constants.ROUTES_COLLECTION,
                 ConnectionStringSetting = Constants.DATABASE_CONNECTION_STRING_SETTING,
                 CreateIfNotExists = true)] IEnumerable <Route> existingRoutes,
            ILogger log)
        {
            try
            {
                var newRoutes = await RoutesHelper.GetRoutesAndUpdateAsync(existingRoutes, routes);

                return(new OkObjectResult(newRoutes));
            }
            catch (Exception exception)
            {
                log.LogError(exception, $"Error during {nameof(RoutesScrapper.GetDataAsync)}");
                return(new InternalServerErrorResult());
            }
        }
Beispiel #2
0
        //[FunctionName("UpdateRoutes")]
        public static async void Run(
            [TimerTrigger("0 0 0 1 * *", RunOnStartup = false)] TimerInfo myTimer,
            [CosmosDB(
                 Constants.DATABASE_NAME,
                 Constants.ROUTES_COLLECTION,
                 ConnectionStringSetting = Constants.DATABASE_CONNECTION_STRING_SETTING,
                 CreateIfNotExists = true)] IAsyncCollector <Route> routes,
            [CosmosDB(
                 Constants.DATABASE_NAME,
                 Constants.ROUTES_COLLECTION,
                 ConnectionStringSetting = Constants.DATABASE_CONNECTION_STRING_SETTING,
                 CreateIfNotExists = true)] IEnumerable <Route> existingRoutes,
            ILogger log)
        {
            log.LogInformation($"{nameof(UpdatesRoutes)} Timer trigger function started at: {DateTime.Now}");

            await RoutesHelper.GetRoutesAndUpdateAsync(existingRoutes, routes);
        }