-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51c11b0
commit cd6d1e9
Showing
24 changed files
with
225 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-github-actions?tabs=dotnet#deploy-the-function-app | ||
|
||
name: Deploy DotNet project to function app with a Linux environment | ||
|
||
on: | ||
[push] | ||
|
||
env: | ||
AZURE_FUNCTIONAPP_NAME: change-event | ||
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.\Messaging' | ||
DOTNET_VERSION: '6.0.x' | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: ${{ env.DOTNET_VERSION }} | ||
|
||
- name: 'Resolve Project Dependencies Using Dotnet' | ||
shell: bash | ||
run: | | ||
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' | ||
dotnet build --configuration Release --output ./output | ||
popd | ||
- name: 'Run Azure Functions Action' | ||
uses: Azure/functions-action@v1 | ||
id: fa | ||
with: | ||
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} | ||
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output' | ||
publish-profile: ${{ secrets.AZURE_MESSAGING_FUNCTIONAPP_PUBLISH_PROFILE }} |
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
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
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
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,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | ||
<AnalysisLevel>latest</AnalysisLevel> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" /> | ||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" /> | ||
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Couple.Shared.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json" CopyToOutputDirectory="PreserveNewest" /> | ||
<None Update="local.settings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" /> | ||
</ItemGroup> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Azure.Messaging.EventGrid; | ||
using Couple.Messaging.Model; | ||
using Couple.Shared.Model; | ||
using Microsoft.Azure.Documents; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.EventGrid; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace Couple.Messaging.Features | ||
{ | ||
public class DeletedEventFunction | ||
{ | ||
[FunctionName("ChangeDeletedEventFunction")] | ||
public async Task Run([CosmosDBTrigger("%DatabaseName%", | ||
"%CollectionName%", | ||
ConnectionStringSetting = "DatabaseConnectionString", | ||
CreateLeaseCollectionIfNotExists = true)] IReadOnlyList<Document> documents, | ||
[EventGrid(TopicEndpointUri = "EventGridEndpoint", | ||
TopicKeySetting = "EventGridKey")] IAsyncCollector<EventGridEvent> eventCollector) | ||
{ | ||
var changes = documents.Select(d => d.ToString()) | ||
.Select(json => JsonSerializer.Deserialize<Change>(json)!) | ||
.Where(change => change.Ttl != -1) | ||
.Where(change => change.Command is Command.CreateImage or Command.UpdateImage) | ||
.ToList(); | ||
|
||
List<Task> tasks = new(); | ||
foreach (var change in changes) | ||
{ | ||
var task = eventCollector.AddAsync(new(change.ContentId.ToString(), "ImageDeleted", "1", new { })); | ||
tasks.Add(task); | ||
} | ||
|
||
await Task.WhenAll(tasks); | ||
} | ||
} | ||
} |
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 @@ | ||
using Azure.Storage.Blobs; | ||
using Couple.Messaging.Model; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.EventGrid; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Couple.Messaging.Features | ||
{ | ||
public class ImageDeletedEventFunction | ||
{ | ||
[FunctionName("ImageDeletedEventFunction")] | ||
public async Task Run([EventGridTrigger] Event @event) | ||
{ | ||
var connectionString = Environment.GetEnvironmentVariable("ImagesConnectionString"); | ||
var client = new BlobClient(connectionString, "images", @event.Subject); | ||
await client.DeleteIfExistsAsync(); | ||
} | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Couple.Messaging.Model | ||
{ | ||
public class Change | ||
{ | ||
public Guid Id { get; init; } | ||
public string? Command { get; init; } | ||
public string? UserId { get; init; } | ||
public DateTime Timestamp { get; init; } | ||
public Guid ContentId { get; init; } | ||
public string? Content { get; init; } | ||
|
||
[JsonPropertyName("ttl")] | ||
public int? Ttl { get; set; } | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Couple.Messaging.Model | ||
{ | ||
public class Event | ||
{ | ||
public string? Topic { get; init; } | ||
public string? Subject { get; init; } | ||
public string? EventType { get; init; } | ||
public DateTime EventTime { get; init; } | ||
public IDictionary<string, object>? Data { get; init; } | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"profiles": { | ||
"Api": { | ||
"commandName": "Executable", | ||
"executablePath": "func", | ||
"commandLineArgs": "start" | ||
} | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.