initial commit
This commit is contained in:
9
.github/config/gitversion.yml
vendored
Normal file
9
.github/config/gitversion.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
next-version: 1.1.0
|
||||
mode: ContinuousDeployment
|
||||
assembly-versioning-scheme: MajorMinorPatch
|
||||
assembly-file-versioning-scheme: MajorMinorPatch
|
||||
|
||||
branches:
|
||||
main:
|
||||
regex: ^main$
|
||||
increment: Patch
|
||||
22
.github/workflows/pull_request_dev.yml
vendored
Normal file
22
.github/workflows/pull_request_dev.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: Build NuGet package on dev branch pull request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "dev"
|
||||
paths:
|
||||
- "TimetableDesigner.Backend.Events.OutboxPattern**"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6.0.2
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
22
.github/workflows/pull_request_main.yml
vendored
Normal file
22
.github/workflows/pull_request_main.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: Build NuGet package on main branch pull request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "main"
|
||||
paths:
|
||||
- "TimetableDesigner.Backend.Events.OutboxPattern**"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6.0.2
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
22
.github/workflows/push_dev.yml
vendored
Normal file
22
.github/workflows/push_dev.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: Build NuGet package on dev branch push
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "dev"
|
||||
paths:
|
||||
- "TimetableDesigner.Backend.Events.OutboxPattern**"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6.0.2
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
72
.github/workflows/push_main.yml
vendored
Normal file
72
.github/workflows/push_main.yml
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
name: Build NuGet package on main branch push
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
paths:
|
||||
- "TimetableDesigner.Backend.Events.OutboxPattern**"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and pack
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Build
|
||||
run: dotnet build
|
||||
- name: Setup GitVersion
|
||||
uses: gittools/actions/gitversion/setup@v4.2.0
|
||||
with:
|
||||
versionSpec: 6.4.x
|
||||
- name: Determine version
|
||||
uses: gittools/actions/gitversion/execute@v4.2.0
|
||||
id: gitversion
|
||||
with:
|
||||
configFilePath: ./.github/config/gitversion.yml
|
||||
- name: Create NuGet package
|
||||
run: dotnet pack -c Release -p:Version=${{steps.gitversion.outputs.SemVer}} -p:PackageVersion=${{steps.gitversion.outputs.SemVer}} --output ${{ github.workspace}}/nuget
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: nuget
|
||||
path: ${{ github.workspace}}/nuget/*.nupkg
|
||||
outputs:
|
||||
version: ${{ steps.gitversion.outputs.SemVer }}
|
||||
publish:
|
||||
name: Publish
|
||||
permissions: write-all
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: nuget
|
||||
path: ${{ github.workspace}}/nuget
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Add source
|
||||
run: dotnet nuget add source --username TimetableDesigner --password ${{secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/TimetableDesigner/index.json"
|
||||
- name: Publish
|
||||
run: dotnet nuget push ${{ github.workspace}}/nuget/*.nupkg --source "github" --api-key ${{ secrets.NUGET_REGISTRY_API_KEY }} --skip-duplicate
|
||||
- name: Create Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{needs.build.outputs.version}}
|
||||
release_name: ${{needs.build.outputs.version}}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
|
||||
289
.gitignore
vendored
Normal file
289
.gitignore
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
# VS Code
|
||||
.vscode/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
3
TimetableDesigner.Backend.Events.OutboxPattern.slnx
Normal file
3
TimetableDesigner.Backend.Events.OutboxPattern.slnx
Normal file
@@ -0,0 +1,3 @@
|
||||
<Solution>
|
||||
<Project Path="TimetableDesigner.Backend.Events.OutboxPattern/TimetableDesigner.Backend.Events.OutboxPattern.csproj" />
|
||||
</Solution>
|
||||
19
TimetableDesigner.Backend.Events.OutboxPattern/Event.cs
Normal file
19
TimetableDesigner.Backend.Events.OutboxPattern/Event.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events.OutboxPattern;
|
||||
|
||||
public class Event
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Payload { get; set; }
|
||||
public required string PayloadType { get; set; }
|
||||
public DateTimeOffset OccuredOn { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset? LastRetryOn { get; set; }
|
||||
public uint RetryCount { get; set; }
|
||||
|
||||
public Event(object payload)
|
||||
{
|
||||
Payload = JsonSerializer.Serialize(payload);
|
||||
PayloadType = payload.GetType().FullName!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events.OutboxPattern;
|
||||
|
||||
public class EventConfiguration : IEntityTypeConfiguration<Event>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Event> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Payload)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.PayloadType)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.OccuredOn)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.LastRetryOn);
|
||||
|
||||
builder.Property(x => x.RetryCount)
|
||||
.IsRequired();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events.OutboxPattern;
|
||||
|
||||
public class EventOutboxSender<TDbContext> : BackgroundService where TDbContext : DbContext, IEventOutboxDbContext
|
||||
{
|
||||
private readonly TDbContext _databaseContext;
|
||||
private readonly IEventQueuePublisher _eventQueuePublisher;
|
||||
|
||||
public EventOutboxSender(TDbContext databaseContext, IEventQueuePublisher eventQueuePublisher)
|
||||
{
|
||||
_databaseContext = databaseContext;
|
||||
_eventQueuePublisher = eventQueuePublisher;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
Event? eventData = await _databaseContext.Events.FirstOrDefaultAsync(x => x.LastRetryOn == null, stoppingToken)
|
||||
?? await _databaseContext.Events.OrderBy(x => x.LastRetryOn).FirstOrDefaultAsync(stoppingToken);
|
||||
|
||||
if (eventData is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Type payloadType = Type.GetType(eventData.PayloadType)!;
|
||||
JsonSerializer.Deserialize(eventData.Payload, payloadType);
|
||||
|
||||
try
|
||||
{
|
||||
await _eventQueuePublisher.PublishAsync(eventData.Payload, payloadType);
|
||||
|
||||
_databaseContext.Events.Remove(eventData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
eventData.LastRetryOn = DateTimeOffset.UtcNow;
|
||||
eventData.RetryCount++;
|
||||
}
|
||||
finally
|
||||
{
|
||||
await _databaseContext.SaveChangesAsync(stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events.OutboxPattern;
|
||||
|
||||
public interface IEventOutboxDbContext
|
||||
{
|
||||
DbSet<Event> Events { get; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version />
|
||||
<Title>TimetableDesigner.Backend.Events.OutboxPattern</Title>
|
||||
<Authors>Mateusz Skoczek</Authors>
|
||||
<PackageProjectUrl>https://github.com/TimetableDesigner</PackageProjectUrl>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<RepositoryUrl>https://github.com/TimetableDesigner/TimetableDesigner.Backend.Events.OutboxPattern</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.2" />
|
||||
<PackageReference Include="TimetableDesigner.Backend.Events" Version="1.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
BIN
TimetableDesigner.Backend.Events.OutboxPattern/icon.png
Normal file
BIN
TimetableDesigner.Backend.Events.OutboxPattern/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Reference in New Issue
Block a user