Exemple #1
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());
        }
Exemple #2
0
        public async Task Run(
            [QueueTrigger("athletes-activities-sync", Connection = "ConnectionStrings:SportClubsChallengeStorage")] string queueItem,
            [Queue("athlete-challenges-update")] CloudQueue updateAthleteChallengesQueue,
            ILogger log)
        {
            log.LogInformation($"Queue trigger function {nameof(SyncAthleteActivities)} processed with item: {queueItem}");

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

            var athlete = await this.db.Athletes.AsNoTracking().FirstOrDefaultAsync(p => p.Id == athleteId);

            if (athlete == null)
            {
                log.LogWarning($"Athlete with id={athleteId} does not exists.");
                return;
            }

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

            log.LogInformation($"Queuing update classification of athlete {athlete.FirstName} {athlete.LastName}.");
            await updateAthleteChallengesQueue.CreateIfNotExistsAsync();

            await updateAthleteChallengesQueue.AddMessageAsync(new CloudQueueMessage(athleteId.ToString()));
        }
        public async Task Run(
            [TimerTrigger("0 0 1 * * *")] TimerInfo myTimer,
            ILogger log)
        {
            log.LogInformation($"Timer trigger function {nameof(SyncAthletesData)} executed at: {DateTime.Now}");

            var job = new GetAthletesActivitiesJob(this.db, this.activityService, this.stravaWrapper, this.tokenService, this.mapper);
            await job.Run();
        }
        private static async Task GetActivities(ServiceProvider services)
        {
            var dbContext       = services.GetRequiredService <SportClubsChallengesDbContext>();
            var stravaWrapper   = services.GetRequiredService <IStravaApiWrapper>();
            var activityService = services.GetRequiredService <IActivityService>();
            var tokenService    = services.GetRequiredService <ITokenService>();
            var mapper          = services.GetRequiredService <IMapper>();

            var job = new GetAthletesActivitiesJob(dbContext, activityService, stravaWrapper, tokenService, mapper);
            await job.Run();
        }