-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy Twitter integration to PROD. (#97)
* Feature/publish to twitter (#95) * Post to Twitter when a word is published. * Upgrade deployment workflow for the API to.NET 8 on all environments. (#96)
- Loading branch information
Showing
23 changed files
with
388 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>15373697-caf3-4a5a-b976-46077b7bff45</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.4" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Application\Application.csproj" /> | ||
<ProjectReference Include="..\Infrastructure.MongoDB\Infrastructure.MongoDB.csproj" /> | ||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Application.Events; | ||
using Core.Cache; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Application.EventHandlers | ||
{ | ||
public class DeletedNameCachingHandler : INotificationHandler<NameDeletedAdapter> | ||
{ | ||
private readonly IRecentIndexesCache _recentIndexesCache; | ||
private readonly IRecentSearchesCache _recentSearchesCache; | ||
private readonly ILogger<DeletedNameCachingHandler> _logger; | ||
|
||
public DeletedNameCachingHandler( | ||
IRecentIndexesCache recentIndexesCache, | ||
IRecentSearchesCache recentSearchesCache, | ||
ILogger<DeletedNameCachingHandler> logger | ||
) | ||
{ | ||
_recentIndexesCache = recentIndexesCache; | ||
_recentSearchesCache = recentSearchesCache; | ||
_logger = logger; | ||
} | ||
|
||
public async Task Handle(NameDeletedAdapter notification, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
await _recentIndexesCache.Remove(notification.Name); | ||
await _recentSearchesCache.Remove(notification.Name); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, "Error occurred while removing deleted name '{name}' from cache.", notification.Name); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Application/EventHandlers/PostPublishedNameCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Application.Events; | ||
using MediatR; | ||
using System.Collections.Concurrent; | ||
|
||
namespace Application.EventHandlers | ||
{ | ||
public class PostPublishedNameCommandHandler : INotificationHandler<PostPublishedNameCommand> | ||
{ | ||
private readonly ConcurrentQueue<PostPublishedNameCommand> _nameQueue; | ||
|
||
public PostPublishedNameCommandHandler(ConcurrentQueue<PostPublishedNameCommand> nameQueue) | ||
{ | ||
_nameQueue = nameQueue; | ||
} | ||
|
||
public Task Handle(PostPublishedNameCommand notification, CancellationToken cancellationToken) | ||
{ | ||
// Enqueue the indexed name for processing by the BackgroundService | ||
_nameQueue.Enqueue(notification); | ||
|
||
// Return a completed task, so it doesn't block the main thread | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using MediatR; | ||
|
||
namespace Application.Events | ||
{ | ||
public record PostPublishedNameCommand(string Name) : INotification | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Infrastructure.Configuration | ||
{ | ||
public record TwitterConfig( | ||
string ConsumerKey, | ||
string ConsumerSecret, | ||
string AccessToken, | ||
string AccessTokenSecret, | ||
string NameUrlPrefix, | ||
string TweetTemplate) | ||
{ | ||
public TwitterConfig() : this("", "", "", "", "", "") { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Infrastructure.Configuration; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Tweetinvi; | ||
|
||
namespace Infrastructure | ||
{ | ||
public static class DependencyInjection | ||
{ | ||
private const string ConfigSectionName = "Twitter"; | ||
|
||
public static IServiceCollection AddTwitterClient(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var config = configuration.GetRequiredSection(ConfigSectionName); | ||
|
||
services.Configure<TwitterConfig>(config); | ||
|
||
services.AddSingleton<ITwitterClient>(provider => | ||
{ | ||
var twitterConfig = config.Get<TwitterConfig>()!; | ||
return new TwitterClient( | ||
twitterConfig.ConsumerKey, | ||
twitterConfig.ConsumerSecret, | ||
twitterConfig.AccessToken, | ||
twitterConfig.AccessTokenSecret | ||
); | ||
}); | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" /> | ||
<PackageReference Include="TweetinviAPI" Version="5.0.4" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Application\Application.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.