public async Task Run( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger) { var repositoryConfigurations = await context.CallActivityWithRetryAsync <IReadOnlyList <RepositoryConfiguration> >( functionName : nameof(GetRepositoryConfigurationsActivity), retryOptions : RetryOptionsBuilder.BuildDefault(), input : null); if (repositoryConfigurations.Any()) { var releasesTasks = GetRepositoryReleasesTasks(context, repositoryConfigurations); var githubReleases = await Task.WhenAll(releasesTasks.GithubReleases); var historyReleases = await Task.WhenAll(releasesTasks.HistoryReleases); var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName(); foreach (var repositoryConfiguration in repositoryConfigurations) { var latestReleases = LatestObjectsBuilder.Build <RepositoryConfiguration, RepositoryRelease, LatestReleases>( repositoryConfiguration, githubReleases, historyReleases, releaseMatchFunction); context.SetCustomStatus(repositoryConfiguration.RepositoryName); latestReleases.IsSaved = await SaveLatestRelease(context, logger, latestReleases); await PostLatestRelease(context, logger, latestReleases); } } }
public void GivenHistoryReleaseIsNullReleaseAndGitHubReleaseIsNullRelease_WhenIsNewAndShouldBeStoredIsCalled_ThenResultShouldBeFalse() { // Arrange const string repoName = "repo"; var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName); var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneNullRelease <GitHubRepositoryRelease>(repoName); var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease <HistoryRepositoryRelease>(repoName); var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName(); // Act var latestReleases = LatestObjectsBuilder.Build <RepositoryConfiguration, RepositoryRelease, LatestReleases>( repoConfig, releasesFromGitHub, releasesFromHistory, releaseMatchFunction); // Assert latestReleases.IsNewAndShouldBeStored.Should().BeFalse("because there is no result from GitHub"); }
public void GivenHistoryReleaseIsReleaseWithNonMatchingReleaseId_WhenIsNewAndShouldBeStoredIsCalled_ThenResultShouldBeTrue() { // Arrange const string repoName = "repo"; const int releaseIdHistory = 1; const int releaseIdGithub = 2; var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName); var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseId <GitHubRepositoryRelease>(repoName, releaseIdGithub); var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseId <HistoryRepositoryRelease>(repoName, releaseIdHistory); var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName(); // Act var latestReleases = LatestObjectsBuilder.Build <RepositoryConfiguration, RepositoryRelease, LatestReleases>( repoConfig, releasesFromGitHub, releasesFromHistory, releaseMatchFunction); // Assert latestReleases.IsNewAndShouldBeStored.Should().BeTrue("because the releaseIds are not equal"); }
public void GivenHistoryReleaseIsNullReleaseAndGitHubReleaseIsWithinTimeWindow_WhenIsNewAndShouldBePostedIsCalled_ThenResultShouldBeTrue() { // Arrange const string repoName = "repo"; const int releaseIdGithub = 1; var daysTimespan = new TimeSpan(1, 0, 0, 0); var gitHubReleaseDate = DateTimeOffset.UtcNow.Subtract(daysTimespan); var repoConfig = RepositoryConfigurationBuilder.BuildOne(repoName); var releasesFromGitHub = RepositoryReleaseBuilder.BuildListContainingOneWithReleaseIdAndDate <GitHubRepositoryRelease>(repoName, releaseIdGithub, gitHubReleaseDate); var releasesFromHistory = RepositoryReleaseBuilder.BuildListContainingOneNullRelease <HistoryRepositoryRelease>(repoName); var releaseMatchFunction = ReleaseFunctionBuilder.BuildForMatchingRepositoryName(); // Act var latestReleases = LatestObjectsBuilder.Build <RepositoryConfiguration, RepositoryRelease, LatestReleases>( repoConfig, releasesFromGitHub, releasesFromHistory, releaseMatchFunction); // Assert latestReleases.IsNewAndShouldBeStored.Should().BeTrue("because the release is not in history yet."); latestReleases.IsNewAndShouldBePosted.Should().BeTrue($"because the release date is within the time window of {LatestReleases.MaximumNumberOfDaysToPostAboutNewlyFoundRelease} days"); }
public async Task Run( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger logger) { logger.LogInformation($"Started {nameof(PublicationUpdateOrchestration)}."); // Read repo links from storage table var publicationConfigurations = await context.CallActivityWithRetryAsync <IReadOnlyList <PublicationConfiguration> >( functionName : nameof(GetPublicationConfigurationsActivity), retryOptions : GetDefaultRetryOptions(), input : null); if (publicationConfigurations.Any()) { var getLatestPublicationsFromWebTasks = new List <Task <Publication> >(); var getLatestPublicationsFromHistoryTasks = new List <Task <Publication> >(); // Fan out over the repos foreach (var publicationConfiguration in publicationConfigurations) { // Get most recent publications from web/RSS getLatestPublicationsFromWebTasks.Add(context.CallActivityWithRetryAsync <Publication>( nameof(GetLatestPublicationFromWebActivity), GetDefaultRetryOptions(), publicationConfiguration)); // Get most recent known publications from history getLatestPublicationsFromHistoryTasks.Add(context.CallActivityWithRetryAsync <Publication>( nameof(GetLatestPublicationFromHistoryActivity), GetDefaultRetryOptions(), publicationConfiguration)); } var latestFromWeb = await Task.WhenAll(getLatestPublicationsFromWebTasks); var latestFromHistory = await Task.WhenAll(getLatestPublicationsFromHistoryTasks); var publicationMatchFunction = PublicationFunctionBuilder.BuildForMatchingPublicationSource(); foreach (var publicationConfiguration in publicationConfigurations) { var latestPublications = LatestObjectsBuilder.Build <PublicationConfiguration, Publication, LatestPublications>( publicationConfiguration, latestFromWeb, latestFromHistory, publicationMatchFunction); logger.LogInformation($"Publication: {publicationConfiguration.PublicationSourceName} " + $"ID: {latestPublications.FromWeb.Id}," + $"IsNewAndShouldBeStored: {latestPublications.IsNewAndShouldBeStored}, " + $"IsNewAndShouldBePosted: {latestPublications.IsNewAndShouldBePosted}."); if (latestPublications.IsNewAndShouldBeStored) { var isSaveSuccessful = await context.CallActivityWithRetryAsync <bool>( nameof(SaveLatestPublicationActivity), GetDefaultRetryOptions(), latestPublications.FromWeb); if (isSaveSuccessful && Toggles.DoPostUpdate && latestPublications.IsNewAndShouldBePosted) { var message = MessageBuilder.BuildForPublication(latestPublications.FromWeb); await context.CallActivityWithRetryAsync <bool>( nameof(PostUpdateActivity), GetDefaultRetryOptions(), message); } } } logger.LogInformation($"Completed {nameof(PublicationUpdateOrchestration)}."); } }