public static async Task Run([TimerTrigger("0 */15 * * * *")] TimerInfo myTimer, [Blob("spitball/AzureSearch/tutor-version.txt")] CloudBlockBlob blob, [AzureSearchSync(TutorSearchWrite.IndexName)] IAsyncCollector <AzureSearchSyncOutput> indexInstance, [Inject] IQueryBus queryBus, ILogger log, CancellationToken token) { var query = new TutorSyncAzureSearchQuery(0); if (await blob.ExistsAsync()) { var str = await blob.DownloadTextAsync(); query = JsonConvert.DeserializeObject <TutorSyncAzureSearchQuery>(str); } var nextQuery = new TutorSyncAzureSearchQuery(query.Version); bool updateOccur; do { updateOccur = false; var result = await queryBus.QueryAsync(query, token); foreach (var update in result.Update) { log.LogInformation($"Sync {update}"); updateOccur = true; var courses = update.Courses?.Where(w => !string.IsNullOrWhiteSpace(w)).Distinct().ToArray() ?? new string[0]; var subjects = update.Subjects?.Where(w => !string.IsNullOrWhiteSpace(w)).ToArray() ?? new string[0]; await indexInstance.AddAsync(new AzureSearchSyncOutput() { Item = new Tutor { Country = update.Country.ToUpperInvariant(), Id = update.UserId.ToString(), Name = update.Name, Courses = courses.ToArray(), Rate = update.Rate, InsertDate = DateTime.UtcNow, Prefix = courses.Union(subjects).Union(new[] { update.Name }) .Distinct(StringComparer.OrdinalIgnoreCase).ToArray(), ReviewCount = update.ReviewsCount, Subjects = subjects.ToArray(), OverAllRating = update.OverAllRating, Data = new TutorCardDto() { UserId = update.UserId, Name = update.Name, Courses = courses.Take(3), Subjects = subjects.OrderBy(o => o).Take(3), ReviewsCount = update.ReviewsCount, Rate = (float)update.Rate, University = update.University, Lessons = Math.Max(update.LessonsCount, update.ReviewsCount), Bio = update.Bio, Price = update.Price, Country = update.Country, Image = update.Image, NeedSerializer = true, DiscountPrice = update.SubsidizedPrice } }, Insert = true }, token); } foreach (var delete in result.Delete) { log.LogInformation($"delete tutor id {delete}"); updateOccur = true; await indexInstance.AddAsync(new AzureSearchSyncOutput() { Item = new Tutor() { Id = delete }, Insert = false }, token); } query.Page++; nextQuery.Version = Math.Max(nextQuery.Version, result.Version); await indexInstance.FlushAsync(token); } while (updateOccur); if (query.Page > 0) { var jsonStr = JsonConvert.SerializeObject(nextQuery); await blob.UploadTextAsync(jsonStr); } log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}"); }
public async Task <IActionResult> LtiAdvantageLaunch( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "lti-advantage-launch/{platformId}")] HttpRequest req, [LtiAdvantage] ILtiResourceLinkRequestClient ltiRequestClient, [LtiAdvantage] INrpsClient nrpsClient, [Platform(PlatformId = "{platformId}")] Platform platform, [Assignment] IAsyncCollector <Assignment> assignmentsCollector, [DurableClient] IDurableEntityClient entityClient, string platformId) { LtiResourceLinkRequest ltiResourceLinkRequest = null; try { ltiResourceLinkRequest = await ltiRequestClient.GetLtiResourceLinkRequest(platform.JwkSetUrl, platform.ClientId, platform.Issuer); } catch (Exception e) { _logger.LogError($"Could not validate request.\n{e}"); } if (ltiResourceLinkRequest == null) { return(new BadRequestErrorMessageResult("Could not validate request.")); } string nonce = ltiResourceLinkRequest.Nonce; string state = req.Form["state"].ToString(); bool isNonceValid = await ValidateNonce(nonce, state, entityClient); if (!isNonceValid) { return(new BadRequestErrorMessageResult("Could not validate nonce.")); } Assignment assignment = ConvertRequestToAssignment(ltiResourceLinkRequest); assignment.PlatformId = platformId; _logger.LogTrace($"Parsed Assignment '{assignment.Name}'."); await assignmentsCollector.AddAsync(assignment); await assignmentsCollector.FlushAsync(); if (string.IsNullOrEmpty(assignment.Id)) { return(new InternalServerErrorResult()); } string asStudentParam = ""; if (ltiResourceLinkRequest.Roles.Contains(Role.ContextLearner) || ltiResourceLinkRequest.Roles.Contains(Role.InstitutionLearner)) { Member launchingMember = await nrpsClient.GetById(platform.ClientId, platform.AccessTokenUrl, platform.Audience, ltiResourceLinkRequest.NamesRoleService.ContextMembershipUrl, ltiResourceLinkRequest.UserId); if (launchingMember != null && (launchingMember.Roles.Contains(Role.ContextInstructor) || launchingMember.Roles.Contains(Role.InstitutionInstructor))) { asStudentParam = "?asStudent"; } } var urlWithParams = $"{RedirectUrl}/{assignment.Id}{asStudentParam}"; _logger.LogInformation($"Redirect to {urlWithParams}"); return(new RedirectResult(urlWithParams)); }
public static async Task Run([ActivityTrigger] RecognitionOrder recognitionOrder, [Queue("modeltraining", Connection = "StorageConnectionString")] IAsyncCollector <RecognitionOrder> queue) { await queue.AddAsync(recognitionOrder); await queue.FlushAsync(); }
public Task Close() { return(_collector.FlushAsync(_cancellationToken)); }
public Task FlushAsync(CancellationToken cancellationToken) { return(_inner.FlushAsync(cancellationToken)); }
public static async Task SayHello([ActivityTrigger] UserInfo userInfo, [Queue("informuserqueue", Connection = "StorageConnectionString")] IAsyncCollector <UserInfo> userInfos) { await userInfos.AddAsync(userInfo); await userInfos.FlushAsync(); }
public async Task SetValueAsync(object value, CancellationToken cancellationToken) { await _raw.FlushAsync(); }
public async Task RunAsync( DateTime importStartDate, DateTime importEndDate, IAsyncCollector <DayInfo> changesPerDayCollection, IAsyncCollector <ProcessDayInfoForTitlesJobWorkerData> outputTitleWorkerStorage, IAsyncCollector <ProcessDayInfoForTitlesJob> outputTitleQueue, TraceWriter log) { // TODO: improve // https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository // https://developer.github.com/v3/#timezones var commits = await _gitHubClient.Repository.Commit.GetAll(GitHubOwner, GitHubRepName, new CommitRequest { Since = importStartDate, Until = importEndDate } ); log.Info($"Processing {commits.Count} commits"); var commitsPerDays = commits.GroupBy(_ => _.Commit.Committer.Date.UtcDateTime.Date); log.Info($"Processing {commitsPerDays.Count()} days"); foreach (var commitsPerDay in commitsPerDays) { var dayInfo = new DayInfo { Id = commitsPerDay.Key, Date = commitsPerDay.Key, DocChanges = new List <DocChange>(), DeepLinksGenerated = true }; foreach (var commitOverview in commitsPerDay) { var commitDetail = await _gitHubClient.Repository.Commit.Get(GitHubOwner, GitHubRepName, commitOverview.Sha); foreach (var file in commitDetail.Files) { AddOrModifyFileChange(commitDetail.Sha, commitDetail.Parents.FirstOrDefault()?.Sha, file, dayInfo.DocChanges, commitOverview.Commit.Committer.Date.UtcDateTime, log); } } if (dayInfo.DocChanges.Count > 0) { await changesPerDayCollection.AddAsync(dayInfo); var filesToProcess = GetAllFiles(dayInfo); if (filesToProcess.Count > 0) { await outputTitleWorkerStorage.AddAsync(new ProcessDayInfoForTitlesJobWorkerData { DayInfoId = dayInfo.Date, FilesToProcess = filesToProcess, }); await outputTitleQueue.AddAsync(new ProcessDayInfoForTitlesJob() { DayInfoId = dayInfo.Date }); } log.Info($"Processed {dayInfo.DocChanges.Count} DocChanges for {dayInfo.Date}"); } else { log.Info($"No DocChanges for {dayInfo.Date}"); } } await changesPerDayCollection.FlushAsync(); }