Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3aba434859 | |||
| 90569c6271 | |||
| b53e856ea2 | |||
| 02c21319e6 | |||
| b343dbe668 | |||
| d4c005602e | |||
| 783ca2e9c5 | |||
| 3d506cffd1 | |||
| cdc373562e | |||
| f299e8952a | |||
| c54695c390 | |||
| c47fef80b3 | |||
| e2d2009cac | |||
| 53b422433c | |||
| 3769bb5bae | |||
| 547f8dd229 | |||
| 13be0eab87 | |||
| 5b8b1684c4 | |||
| e19f98e7ca | |||
| 8a8ed98a91 | |||
| 4b8aecc779 | |||
| f4a350b2e3 | |||
| e61f628804 | |||
| 56dbe85868 | |||
| 8fa3ac7546 | |||
| e238dcce59 | |||
| 88e70b1e81 | |||
| 36dc31e85b | |||
| 41f92d0670 | |||
| e9a1552e6d | |||
| 988ba4113c | |||
| f62ac1bc71 | |||
| 544eef0e49 | |||
| a7b9e945a3 | |||
| 4a20c5ea5f | |||
| 6f5892c228 | |||
| 23d992704e | |||
| 581cd2084a | |||
| 87bfc65b34 | |||
| aef2884e8e | |||
| c18635a0d4 | |||
| 84597be935 | |||
| 13370ccb7f | |||
| ce7bcd20ac | |||
| d84de56a9d | |||
| d7215ff278 | |||
| d934cc6251 |
+25
-6
@@ -31,20 +31,37 @@ steps:
|
||||
registry: nexus.khongisa.co.za
|
||||
repo: nexus.khongisa.co.za/litecharms-scheduler
|
||||
tags: [ latest, "1.${DRONE_BUILD_NUMBER}" ]
|
||||
custom_labels:
|
||||
- org.opencontainers.image.source=https://gitea.khongisa.co.za/litecharms/scheduler
|
||||
- org.opencontainers.image.version=1.${DRONE_BUILD_NUMBER}
|
||||
- org.opencontainers.image.revision=${DRONE_COMMIT_SHA}
|
||||
username: { from_secret: docker_username }
|
||||
password: { from_secret: docker_password }
|
||||
|
||||
- name: gitea-tag
|
||||
|
||||
- name: gitea-tag-release
|
||||
image: alpine/git
|
||||
environment:
|
||||
GITEA_TOKEN: { from_secret: git_token }
|
||||
GITEA_USER: { from_secret: git_username }
|
||||
GITEA_PASS: { from_secret: git_password }
|
||||
commands:
|
||||
- git config --global user.email "drone@litecharms.co.za"
|
||||
- git config --global user.name "Drone CI"
|
||||
- echo "169.255.58.144 gitea.khongisa.co.za" >> /etc/hosts
|
||||
- apk add --no-cache curl
|
||||
- git remote set-url origin https://$${GITEA_USER}:$${GITEA_PASS}@gitea.khongisa.co.za/litecharms/scheduler.git
|
||||
- git tag 1.${DRONE_BUILD_NUMBER}
|
||||
- git push origin 1.${DRONE_BUILD_NUMBER}
|
||||
- |
|
||||
curl -X POST "https://gitea.khongisa.co.za/api/v1/repos/litecharms/scheduler/releases" \
|
||||
-H "Authorization: token $${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"tag_name\": \"1.${DRONE_BUILD_NUMBER}\",
|
||||
\"target_commitish\": \"${DRONE_COMMIT_SHA}\",
|
||||
\"name\": \"Release 1.${DRONE_BUILD_NUMBER}\",
|
||||
\"body\": \"### Artifacts\n* **Docker Image:** nexus.khongisa.co.za/litecharms-scheduler:1.${DRONE_BUILD_NUMBER}\n* **NuGet:** [View on Nexus](https://nexus.khongisa.co.za/repository/nuget-group/)\",
|
||||
\"draft\": false,
|
||||
\"prerelease\": false
|
||||
}"
|
||||
|
||||
depends_on:
|
||||
- build
|
||||
@@ -66,7 +83,8 @@ steps:
|
||||
- mkdir -p $HOME/.kube
|
||||
- echo "$KUBE_CONFIG" > $HOME/.kube/config
|
||||
- kubectl apply -f litecharms-scheduler-uat.yml
|
||||
- kubectl rollout restart deployment/litecharms-scheduler-uat -n litecharms-scheduler-uat
|
||||
- sleep 10
|
||||
- kubectl rollout restart statefulset/litecharms-scheduler-uat -n litecharms-scheduler-uat
|
||||
|
||||
depends_on:
|
||||
- package
|
||||
@@ -88,7 +106,8 @@ steps:
|
||||
- mkdir -p $HOME/.kube
|
||||
- echo "$KUBE_CONFIG" > $HOME/.kube/config
|
||||
- kubectl apply -f litecharms-scheduler.yml
|
||||
- kubectl rollout restart shop/deployment/litecharms-scheduler -n litecharms-scheduler
|
||||
- sleep 10
|
||||
- kubectl rollout restart statefulset/litecharms-scheduler -n litecharms-scheduler
|
||||
|
||||
depends_on:
|
||||
- uat
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteCharms.Abstractions" Version="1.13.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
|
||||
<PackageReference Include="LiteCharms.Features.MidrandBooks" Version="1.70.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
|
||||
<PackageReference Include="Mediator.SourceGenerator" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
@@ -18,13 +18,12 @@
|
||||
|
||||
<!-- Lite Charms Libraries -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteCharms.Extensions" Version="1.13.0" />
|
||||
<PackageReference Include="LiteCharms.Features" Version="1.13.0" />
|
||||
<PackageReference Include="LiteCharms.Models" Version="1.13.0" />
|
||||
<PackageReference Include="LiteCharms.Features" Version="1.70.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Shared Global Usings -->
|
||||
<ItemGroup>
|
||||
<Using Include="Quartz" />
|
||||
<Using Include="Mediator" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
using LiteCharms.Extensions;
|
||||
using LiteCharms.Features.Extensions;
|
||||
using LiteCharms.Features.Mediator;
|
||||
using LiteCharms.Features.MidrandBooks.Extensions;
|
||||
using LiteCharmsScheduler.Workers;
|
||||
using static LiteCharms.Abstractions.Constants;
|
||||
using static LiteCharms.Features.Extensions.Quartz;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddMediator();
|
||||
builder.Services.AddEmailServiceBus();
|
||||
builder.Services.AddSalesServiceBus();
|
||||
builder.Services.AddGeneralServiceBus();
|
||||
builder.Services.AddEmailServices(builder.Configuration);
|
||||
builder.Services.AddShopDatabase(builder.Configuration);
|
||||
builder.Services.AddQuartzSchedulerClient(ShopSchedulerName, ShopSchedulerInstanceId, builder.Configuration);
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TelemetryPipelineBehavior<,>));
|
||||
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingPipelineBehavior<,>));
|
||||
|
||||
builder.Services.AddEmailServices(builder.Configuration);
|
||||
builder.Services.AddEmailServiceBus();
|
||||
|
||||
builder.Services.AddShopServices();
|
||||
builder.Services.AddHashServices(builder.Configuration);
|
||||
builder.Services.AddMidrandShopDatabase(builder.Configuration);
|
||||
|
||||
builder.Services.AddQuartzScheduler(MidrandShopSchedulerName, builder.Configuration);
|
||||
|
||||
builder.Services.AddHostedService<JobWorker>();
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
var schedulerFactory = host.Services.GetRequiredService<ISchedulerFactory>();
|
||||
var scheduler = await schedulerFactory.GetScheduler(ShopSchedulerName);
|
||||
var scheduler = await schedulerFactory.GetScheduler(MidrandShopSchedulerName);
|
||||
|
||||
if (!scheduler!.IsStarted)
|
||||
await scheduler.Start();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace LiteCharmsScheduler.Workers
|
||||
{
|
||||
public class JobWorker(ILogger<JobWorker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) =>
|
||||
logger.LogInformation("Midrand Books jobs initialized");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace LiteCharmsScheduler.Workers
|
||||
{
|
||||
public class Worker(ILogger<Worker> logger) : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,24 @@
|
||||
{
|
||||
"Email": {
|
||||
"Credentials": {
|
||||
"Username": "shop@litecharms.co.za"
|
||||
},
|
||||
"Port": 465,
|
||||
"Host": "mail.litecharms.co.za",
|
||||
"UseSsl": true
|
||||
"HasherSettings": {
|
||||
"MinHashLength": 11
|
||||
},
|
||||
"BookshopS3Settings": {
|
||||
"ServiceUrl": "http://192.168.1.177:30900",
|
||||
"Region": "garage",
|
||||
"BucketName": "bookshop",
|
||||
"CdnBaseUrl": "https://bookshop.cdn.khongisa.co.za"
|
||||
},
|
||||
"Monitoring": {
|
||||
"ApiKey": "",
|
||||
"Address": "http://aspire-dashboard-service.aspire.svc.cluster.local:18889",
|
||||
"ServiceName": "LiteCharms.LeadGenerator"
|
||||
"ServiceName": "MidrandBooks.DEV"
|
||||
},
|
||||
"EmailProcessorCron": "0 */5 * * * ?",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
# LiteCharms
|
||||
# LiteCharms.Scheduler
|
||||
|
||||
The background processing engine responsible for automated tasks and scheduled jobs.
|
||||
|
||||
## 🏗 Architecture
|
||||
* **Type:** Kubernetes **StatefulSet**
|
||||
* **Persistence:** Uses Postgres at `192.168.1.170`.
|
||||
* **Clustering:** Configured for Quartz.NET/Hangfire clustering to support multiple replicas without task duplication.
|
||||
|
||||
## 🚀 CI/CD Workflow
|
||||
* **Trigger:** Pull Request to `master`.
|
||||
* **Versioning:** Automated Gitea Releases with links to Docker and NuGet artifacts.
|
||||
* **Identity:** Uses stable network identifiers (`litecharms-scheduler-0`, etc.) to maintain lock integrity in the database.
|
||||
|
||||
## ⚙️ Scaling
|
||||
To scale the scheduler:
|
||||
`kubectl scale statefulset litecharms-scheduler --replicas=3`
|
||||
*Note: Ensure Database Job Store is enabled in appsettings before scaling.*
|
||||
@@ -17,6 +17,19 @@ data:
|
||||
Email__Host: "mail.litecharms.co.za"
|
||||
Email__Port: "465"
|
||||
Email__UseSsl: "true"
|
||||
EmailProcessorCron: "0 */5 * * * ?"
|
||||
HasherSettings__MinHashLength: "11"
|
||||
BookshopS3Settings__ServiceUrl: "http://garage.garage.svc.cluster.local:3900"
|
||||
BookshopS3Settings__Region: "garage"
|
||||
BookshopS3Settings__BucketName: "bookshop"
|
||||
BookshopS3Settings__CdnBaseUrl: "https://bookshop.cdn.khongisa.co.za"
|
||||
ValidPayfastHosts__0: "www.payfast.co.za"
|
||||
ValidPayfastHosts__1: "sandbox.payfast.co.za"
|
||||
ValidPayfastHosts__2: "w1w.payfast.co.za"
|
||||
ValidPayfastHosts__3: "w2w.payfast.co.za"
|
||||
ValidPayfastHosts__4: "ips.payfast.co.za"
|
||||
ValidPayfastHosts__5: "api.payfast.co.za"
|
||||
ValidPayfastHosts__6: "payment.payfast.io"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
@@ -25,31 +38,36 @@ metadata:
|
||||
namespace: litecharms-scheduler-uat
|
||||
type: Opaque
|
||||
data:
|
||||
connection-string: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPWxlYWRnZW5lcmF0b3ItZGV2O1VzZXJuYW1lPWxlYWRnZW5lcmF0b3I7UGFzc3dvcmQ9S2VLNDRsczRQWHBuYms7UGVyc2lzdCBTZWN1cml0eSBJbmZvPVRydWU=
|
||||
connection-string-quartz: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPXNjaGVkdWxlci1kZXY7VXNlcm5hbWU9c2NoZWR1bGVyLWRldi11c2VyO1Bhc3N3b3JkPWtWVm1vV0tKM3h6Z1FYO1BlcnNpc3QgU2VjdXJpdHkgSW5mbz1UcnVl
|
||||
connection-string: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPW1pZHJhbmRzaG9wLWRldjtVc2VybmFtZT1taWRyYW5kc2hvcC1kZXYtdXNlcjtQYXNzd29yZD1hUFh5a0tnM3RTOWNtRDtQZXJzaXN0IFNlY3VyaXR5IEluZm89VHJ1ZQ==
|
||||
discord-webhook: aHR0cHM6Ly9kaXNjb3JkLmNvbS9hcGkvd2ViaG9va3MvMTUwMDIzMzEyOTYwNzAzNjk3MC9KYzc5endwMjlxYWpLbmoyYkR3cm5GR0RJci11ZGIyV2JIUDZTYjdpT0hCTWpQSUY3Vkw5eUVHTkJUSXpSOVVWVzI0bQ==
|
||||
aspire-apikey: bWMzRzYzSzJqNVpPRXNpMEFqTW9qTFRYbTFLRVpGY3R6SUlqU3dEaVRHdXQ4cUdTa1B1V3d4R1AxUmJzY0pVbw==
|
||||
email-password: JFpTLWVJQGlYbTVNUCRhfg==
|
||||
quartz-store: SG9zdD0xOTIuMTY4LjEuMTcwO0RhdGFiYXNlPXNjaGVkdWxlci1kZXY7VXNlcm5hbWU9c2NoZWR1bGVyLWRldi11c2VyO1Bhc3N3b3JkPWtWVm1vV0tKM3h6Z1FYO1BlcnNpc3QpU2VjdXJpdHkgSW5mbz1UcnVl
|
||||
hasher-salt: VEdsbmFIUWdRMmhoY20xekxDQk5hV1J5WVc1a1FtOXZhM01nYldGclpTQnNiM1J6SUc5bUlHMXZibVY1SUdGdVpDQmhjbVVnWVNCemRXTmpaWE56Wm5Wc0lIWnBjbUZzSUhOMGIzSjVJR2x1SUZOdmRYUm9JRUZtY21sallRPT0=
|
||||
hasher-payfastpassphrase: OUdBSVIwdFdwaFgwcU8=
|
||||
bookshop-s3-accesskey: R0s1MTRkMmNlOGRjNjkyMzdhMDVjMDFlZWY=
|
||||
bookshop-s3-secretkey: ZWFhZmVkYTFhZWQ0MDllY2ZlNjA3MTRlY2RhNTQ5YjgyYmRmNWEzZGFmOWYxOGRkNjFmNjZiNDk3M2E2NDgyZQ==
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
kind: Service
|
||||
metadata:
|
||||
name: scheduler-data-pvc
|
||||
name: scheduler-worker-service
|
||||
namespace: litecharms-scheduler-uat
|
||||
spec:
|
||||
accessModes: ["ReadWriteMany"]
|
||||
storageClassName: nfs-storage
|
||||
resources:
|
||||
requests:
|
||||
storage: 2Gi
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: scheduler
|
||||
ports:
|
||||
- port: 80
|
||||
name: dummy-port
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: litecharms-scheduler
|
||||
name: litecharms-scheduler-uat
|
||||
namespace: litecharms-scheduler-uat
|
||||
spec:
|
||||
serviceName: "scheduler-worker"
|
||||
serviceName: "scheduler-worker-service"
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
@@ -62,6 +80,7 @@ spec:
|
||||
containers:
|
||||
- name: scheduler
|
||||
image: nexus.khongisa.co.za/litecharms-scheduler:latest
|
||||
imagePullPolicy: Always
|
||||
resources:
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
@@ -73,6 +92,36 @@ spec:
|
||||
- configMapRef:
|
||||
name: scheduler-config
|
||||
env:
|
||||
- name: BookshopS3Settings__AccessKey
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: bookshop-s3-accesskey
|
||||
- name: BookshopS3Settings__SecretKey
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: bookshop-s3-secretkey
|
||||
- name: HasherSettings__Salt
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: hasher-salt
|
||||
- name: HasherSettings__PayfastPassphrase
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: hasher-payfastpassphrase
|
||||
- name: ConnectionStrings__PostgresMidrandBooks
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: connection-string
|
||||
- name: Monitoring__ApiKey
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: aspire-apikey
|
||||
- name: Email__Credentials__Password
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
@@ -82,12 +131,7 @@ spec:
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: quartz-store
|
||||
- name: ConnectionStrings__PostgresShop
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: connection-string
|
||||
key: connection-string-quartz
|
||||
- name: ConnectionStrings__DiscordShop
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
@@ -98,22 +142,3 @@ spec:
|
||||
secretKeyRef:
|
||||
name: scheduler-secrets
|
||||
key: aspire-apikey
|
||||
volumeMounts:
|
||||
- name: storage
|
||||
mountPath: /app/wwwroot/content
|
||||
subPath: content
|
||||
- name: storage
|
||||
mountPath: /app/keys
|
||||
subPath: dataprotection-keys
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- ps aux | grep LiteCharmsScheduler.dll | grep -v grep
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 60
|
||||
volumes:
|
||||
- name: storage
|
||||
persistentVolumeClaim:
|
||||
claimName: scheduler-data-pvc
|
||||
|
||||
Reference in New Issue
Block a user