public static async Task Run(
            [TimerTrigger("0 * * * * *")] TimerInfo myTimer,
            [Queue("contestprogress-update", Connection = "AzureStorageOptions:ConnectionString")] ICollector <ContestProgressUpdate> contestProgressUpdates,
            ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var contestLister =
                new ContestLister(
                    ObjectFactory.CreateMapper(),
                    ObjectFactory.CreateContestRepository());

            var contests =
                await contestLister.ExecuteAsync(
                    new ContestList
            {
                Status = ContestStatus.InProgress
            });

            foreach (var contest in contests
                     .Where(x => x.NextProgressUpdateOn <= DateTime.UtcNow))
            {
                contestProgressUpdates.Add(
                    new ContestProgressUpdate
                {
                    Id = contest.Id
                });

                log.LogInformation(JsonConvert.SerializeObject(contest, Formatting.Indented));
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "contests/numberoflearners")] HttpRequest req,
            [Queue("contestnumberoflearners-update", Connection = "AzureStorageOptions:ConnectionString")] ICollector <ContestNumberOfLearnersUpdate> contestNumberOfLearnersUpdates,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var contestLister =
                new ContestLister(
                    ObjectFactory.CreateMapper(),
                    ObjectFactory.CreateContestRepository());

            var contests =
                await contestLister.ExecuteAsync(
                    new ContestList());

            foreach (var contest in contests)
            {
                var contestNumberOfLearnersUpdate =
                    new ContestNumberOfLearnersUpdate
                {
                    ContestId = contest.Id
                };

                log.LogInformation(
                    JsonConvert.SerializeObject(contestNumberOfLearnersUpdate, Formatting.Indented));

                contestNumberOfLearnersUpdates.Add(
                    contestNumberOfLearnersUpdate);
            }

            return(new OkResult());
        }
Exemplo n.º 3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "contests/progress")] HttpRequest req,
            [Queue("contestprogress-update", Connection = "AzureStorageOptions:ConnectionString")] ICollector <ContestProgressUpdate> contestProgressUpdates,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var contestLister =
                new ContestLister(
                    ObjectFactory.CreateMapper(),
                    ObjectFactory.CreateContestRepository());

            var contests =
                await contestLister.ExecuteAsync(
                    new ContestList
            {
                Status = ContestStatus.InProgress
            });

            foreach (var contest in contests)
            {
                contestProgressUpdates.Add(
                    new ContestProgressUpdate
                {
                    Id = contest.Id
                });
            }

            return(new OkResult());
        }
Exemplo n.º 4
0
        public static async Task Run(
            [TimerTrigger("0 0 */1 * * *")] TimerInfo myTimer,
            ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var contestLister =
                new ContestLister(
                    ObjectFactory.CreateMapper(),
                    ObjectFactory.CreateContestRepository());

            var contests =
                await contestLister.ExecuteAsync(
                    new ContestList
            {
                Status = ContestStatus.InProgress
            });

            foreach (var contest in contests
                     .Where(x => x.EndDate <= DateTime.UtcNow))
            {
                var contestEnder =
                    new ContestEnder(
                        ObjectFactory.CreateMapper(),
                        ObjectFactory.CreateContestRepository());

                await contestEnder.ExecuteAsync(
                    new ContestEnd
                {
                    Id = contest.Id
                });

                log.LogInformation(JsonConvert.SerializeObject(contest, Formatting.Indented));
            }
        }
        public static async Task Run(
            [TimerTrigger("0 0 * * * *", RunOnStartup = true, UseMonitor = false)] TimerInfo myTimer,
            [Queue("conteststatus-update", Connection = "AzureStorageOptions:ConnectionString")] ICollector <ContestStatusUpdate> contestStatusUpdates,
            ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            var contestLister =
                new ContestLister(
                    ObjectFactory.CreateMapper(),
                    ObjectFactory.CreateContestRepository());

            var readyContests =
                await contestLister.ExecuteAsync(
                    new ContestList
            {
                Status = ContestStatus.Ready
            });

            foreach (var contest in readyContests
                     .Where(x => x.StartDate <= DateTime.UtcNow))
            {
                contestStatusUpdates.Add(
                    new ContestStatusUpdate
                {
                    Id = contest.Id
                });
            }

            var inProgressContests =
                await contestLister.ExecuteAsync(
                    new ContestList
            {
                Status = ContestStatus.InProgress
            });

            foreach (var contest in inProgressContests
                     .Where(x => x.EndDate <= DateTime.UtcNow))
            {
                contestStatusUpdates.Add(
                    new ContestStatusUpdate
                {
                    Id = contest.Id
                });
            }
        }