Esempio n. 1
0
        private static async Task UpdateClassifications(ServiceProvider services)
        {
            var dbContext = services.GetRequiredService <SportClubsChallengesDbContext>();

            var job = new UpdateChallengesClassificationsJob(dbContext);
            await job.Run();
        }
Esempio n. 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("HTTP trigger function {0}.", nameof(SyncAllData));

            var activitiesJob = new GetAthletesActivitiesJob(this.db, this.activityService, this.stravaWrapper, this.tokenService, this.mapper);
            await activitiesJob.Run();

            var athletes = await this.db.Athletes.ToListAsync();

            foreach (var athlete in athletes)
            {
                var clubsJob = new GetAthletesClubsJob(this.db, this.stravaWrapper, this.tokenService, this.mapper);
                await clubsJob.Run(athlete.Id);
            }

            var activeChallenges = await this.db.Challenges.Where(p => p.IsActive).ToListAsync();

            foreach (var challenge in activeChallenges)
            {
                var classificationsJob = new UpdateChallengesClassificationsJob(this.db);
                await classificationsJob.Run(challenge.Id);
            }

            return(new OkResult());
        }
        public async Task Run(
            [QueueTrigger("challenges-rank-update", Connection = "ConnectionStrings:SportClubsChallengeStorage")] string queueItem,
            ILogger log)
        {
            log.LogInformation($"Queue trigger function {nameof(UpdateChallengeClassification)} processed with item: {queueItem}");

            if (string.IsNullOrEmpty(queueItem) || !long.TryParse(queueItem, out long challengeId))
            {
                log.LogError($"Cannot parse '{queueItem}' to challenge identifier.");
                return;
            }

            var challenge = await this.db.Challenges.AsNoTracking().FirstOrDefaultAsync(p => p.Id == challengeId);

            if (challenge == null)
            {
                log.LogWarning($"Challenge with id={challengeId} does not exists.");
                return;
            }

            log.LogInformation($"Updating classification of challenge '{challenge.Name}'");

            var job = new UpdateChallengesClassificationsJob(this.db);
            await job.Run(challengeId);
        }
Esempio n. 4
0
        public async Task RunAsync(
            [TimerTrigger("0 0 2 * * *")] TimerInfo myTimer,
            ILogger log)
        {
            log.LogInformation($"Timer trigger function {nameof(UpdateChallenges)} executed at: {DateTime.Now}");

            var activeChallenges = await this.db.Challenges.Where(p => p.IsActive).ToListAsync();

            foreach (var challenge in activeChallenges)
            {
                log.LogDebug($"Update classification of '{challenge.Name}' challenge");
                var job = new UpdateChallengesClassificationsJob(this.db);
                await job.Run(challenge.Id);
            }

            log.LogDebug($"Deactivate past challenges");
            var deactivateJob = new DeactivateChallengesJob(this.db);
            await deactivateJob.Run();
        }