Skip to content

Commit 90430c5

Browse files
committed
Split into seperate workflows to improve observability
1 parent 1077666 commit 90430c5

File tree

5 files changed

+67
-15
lines changed

5 files changed

+67
-15
lines changed

website/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export default [
1010
"/upload-from-weather-station/:secret",
1111
"./routes/uploadFromWeatherStation.ts"
1212
),
13-
route("/download", "./routes/download.ts"),
13+
route("/download", "./routes/download.tsx"),
1414
layout("./routes/layout.tsx", [index("./routes/index.tsx")]),
1515
] satisfies RouteConfig;

website/app/routes/uploadFromWeatherStation.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { data } from "react-router";
22
import {
33
observationFromWeatherStation,
44
observationInsertSchema,
5-
Observations,
65
} from "../../database/schema.d";
76
import type { Route } from "./+types/uploadFromWeatherStation";
87

@@ -85,14 +84,22 @@ export async function action({ request, context, params }: Route.LoaderArgs) {
8584
});
8685
} else {
8786
// The data is valid, so we need to insert it into the database
88-
const workflowInstance =
89-
await context.cloudflare.env.WORKFLOW_HANDLE_RECEIVED_OBSERVATION.create({
87+
await context.cloudflare.env.WORKFLOW_UPLOAD_RECEIVED_OBSERVATION_TO_DB.create(
88+
{
9089
params: fullValidation.data,
91-
});
92-
const workflowStatus = await workflowInstance.status();
90+
}
91+
);
92+
await context.cloudflare.env.WORKFLOW_UPLOAD_TO_METOFFICE.create({
93+
params: fullValidation.data,
94+
});
95+
await context.cloudflare.env.WORKFLOW_UPLOAD_TO_WINDGURU.create({
96+
params: fullValidation.data,
97+
});
98+
await context.cloudflare.env.WORKFLOW_UPLOAD_TO_WINDY.create({
99+
params: fullValidation.data,
100+
});
93101
return data({
94102
message: "Observation received",
95-
status: workflowStatus.status,
96103
});
97104
}
98105
}

website/worker-configuration.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
// Generated by Wrangler by running `wrangler types` (hash: 85699d413fb8f19b191b43ace5ddd221)
1+
// Generated by Wrangler by running `wrangler types` (hash: 7b4d44cc09fc21104015bfeac3c0ef1c)
22
// Runtime types generated with workerd@1.20250405.0 2025-04-05 nodejs_compat
33
declare namespace Cloudflare {
44
interface Env {
55
KV: KVNamespace;
66
R2_BUCKET: R2Bucket;
77
DB: D1Database;
88
CF_VERSION_METADATA: { id: string; tag: string };
9-
WORKFLOW_HANDLE_RECEIVED_OBSERVATION: Workflow;
9+
WORKFLOW_UPLOAD_RECEIVED_OBSERVATION_TO_DB: Workflow;
1010
WORKFLOW_HANDLE_DISREGARD_OBSERVATION: Workflow;
1111
WORKFLOW_OVERNIGHT_SAVE_TO_R2: Workflow;
12+
WORKFLOW_UPLOAD_TO_WINDGURU: Workflow;
13+
WORKFLOW_UPLOAD_TO_METOFFICE: Workflow;
14+
WORKFLOW_UPLOAD_TO_WINDY: Workflow;
1215
}
1316
}
1417
interface Env extends Cloudflare.Env {}

website/workers/app.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export default {
4747
},
4848
} satisfies ExportedHandler<Env>;
4949

50-
export class HandleReceivedObservation extends WorkflowEntrypoint<
50+
export class UploadReceivedObservation extends WorkflowEntrypoint<
5151
Env,
5252
schema.ObservationInsert
5353
> {
5454
async run(
5555
event: WorkflowEvent<schema.ObservationInsert>,
5656
step: WorkflowStep
5757
) {
58-
const upload = await step.do(
58+
await step.do(
5959
"Upload incoming data into database",
6060
{
6161
retries: {
@@ -88,6 +88,17 @@ export class HandleReceivedObservation extends WorkflowEntrypoint<
8888
};
8989
}
9090
);
91+
}
92+
}
93+
94+
export class UploadToWindGuru extends WorkflowEntrypoint<
95+
Env,
96+
schema.ObservationInsert
97+
> {
98+
async run(
99+
event: WorkflowEvent<schema.ObservationInsert>,
100+
step: WorkflowStep
101+
) {
91102
await step.do(
92103
"Upload to WindGuru",
93104
{
@@ -144,6 +155,17 @@ export class HandleReceivedObservation extends WorkflowEntrypoint<
144155
}
145156
}
146157
);
158+
}
159+
}
160+
161+
export class UploadToMetOffice extends WorkflowEntrypoint<
162+
Env,
163+
schema.ObservationInsert
164+
> {
165+
async run(
166+
event: WorkflowEvent<schema.ObservationInsert>,
167+
step: WorkflowStep
168+
) {
147169
await step.do(
148170
"Upload to Met Office",
149171
{
@@ -209,6 +231,17 @@ export class HandleReceivedObservation extends WorkflowEntrypoint<
209231
);
210232
}
211233
);
234+
}
235+
}
236+
237+
export class UploadToWindy extends WorkflowEntrypoint<
238+
Env,
239+
schema.ObservationInsert
240+
> {
241+
async run(
242+
event: WorkflowEvent<schema.ObservationInsert>,
243+
step: WorkflowStep
244+
) {
212245
await step.do(
213246
"Upload to Windy",
214247
{

website/wrangler.jsonc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@
1818
],
1919
"workflows": [
2020
{
21-
"name": "PSCWeather-HandleReceivedObservation",
22-
"binding": "WORKFLOW_HANDLE_RECEIVED_OBSERVATION",
23-
"class_name": "HandleReceivedObservation"
21+
"name": "PSCWeather-UploadReceivedObservationToDB",
22+
"binding": "WORKFLOW_UPLOAD_RECEIVED_OBSERVATION_TO_DB",
23+
"class_name": "UploadReceivedObservation"
2424
},
2525
{
26-
"name": "PSCWeather-DisregardReceivedObservation",
2726
"binding": "WORKFLOW_HANDLE_DISREGARD_OBSERVATION",
2827
"class_name": "DisregardReceivedObservation"
2928
},
3029
{
3130
"name": "PSCWeather-SaveToR2Overnight",
3231
"binding": "WORKFLOW_OVERNIGHT_SAVE_TO_R2",
3332
"class_name": "OvernightSaveToR2"
33+
},
34+
{
35+
"name": "PSCWeather-UploadReceivedObservationToMetOffice",
36+
"binding": "WORKFLOW_UPLOAD_TO_METOFFICE",
37+
"class_name": "UploadToMetOffice"
38+
},
39+
{
40+
"name": "PSCWeather-UploadReceivedObservationToWindy",
41+
"binding": "WORKFLOW_UPLOAD_TO_WINDY",
42+
"class_name": "UploadToWindy"
3443
}
3544
],
3645
"r2_buckets": [

0 commit comments

Comments
 (0)