Skip to content

Commit

Permalink
Worker refactor (#863)
Browse files Browse the repository at this point in the history
- Parse variables before processing request to cut out code duplication
- Make the webpage a bit more fancy and use JS to show a local time
- Add some basic tests + CI workflow
  • Loading branch information
SapiensAnatis authored Jun 8, 2024
1 parent f64255a commit 75aac78
Show file tree
Hide file tree
Showing 16 changed files with 2,250 additions and 196 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-api.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test API
name: Test DragaliaAPI

on:
push:
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/test-worker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test MaintenanceWorker

on:
pull_request:
branches:
- main
paths:
- MaintenanceWorker/**

jobs:
vitest:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: MaintenanceWorker

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
working-directory: MaintenanceWorker
run: pnpm install

- name: Build
working-directory: MaintenanceWorker
run: pnpm exec wrangler deploy --dry-run

- name: Test
working-directory: MaintenanceWorker
run: pnpm run test
36 changes: 18 additions & 18 deletions MaintenanceWorker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions MaintenanceWorker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ This is a Cloudflare Worker written in Rust to show the in-game maintenance aler

While the existing server can handle maintenance alerts [via MaintenanceOptions](https://github.com/SapiensAnatis/Dawnshard/blob/main/DragaliaAPI/DragaliaAPI/appsettings.json#L113), it cannot do this if it needs to be taken down entirely, or if the container host needs to be restarted. A Cloudflare worker allows us to return maintenance information regardless of the status of the API.

The maintenance data is configured in `wrangler.toml`, e.g.
The maintenance data is configured in `wrangler.toml`. Below is an example configuration. All values are required.

```toml
[vars]
MAINTENANCE_END_DATE = "2024-05-20T18:14:08Z"
MAINTENANCE_END_DATE = "2024-05-20T18:14:08Z" # Must be ISO 8601 format.
MAINTENANCE_TITLE = "Maintenance"
MAINTENANCE_BODY = "Dawnshard is currently under maintenance\nto upgrade the server."
```

## Development

1. Install dependencies:

```bash
pnpm i
```

## Deployment to production

2. Start the worker in development:

```bash
pnpm run
```
10 changes: 9 additions & 1 deletion MaintenanceWorker/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"name": "maintenance-worker",
"packageManager": "[email protected]",
"version": "1.0.0",
"description": "Cloudflare worker for showing the maintenance screen even if the origin server is down",
"devDependencies": {
"@msgpack/msgpack": "3.0.0-beta2",
"@types/jest": "29.5.12",
"miniflare": "3.20240605.0",
"vitest": "1.6.0",
"vitest-environment-miniflare": "2.14.2",
"wrangler": "3.57.0"
},
"type": "module",
"scripts": {
"start": "npx wrangler dev"
"start": "pnpm exec wrangler dev",
"test": "pnpm exec vitest run"
}
}
Loading

0 comments on commit 75aac78

Please sign in to comment.