| 1 | import * as GCP from "alchemy/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | /** The warehouse every scheduled run reports into. */ |
| 5 | export const Monitoring = GCP.BigQuery.Dataset("Monitoring", { |
| 6 | forceDestroy: true, |
| 7 | }); |
| 8 | |
| 9 | /** |
| 10 | * One row per scheduled run. `kind` says which schedule fired, and |
| 11 | * `value` is what that run computed: the delivery lag for a heartbeat, |
| 12 | * the number of heartbeats seen in the last day for the daily rollup. |
| 13 | */ |
| 14 | export const Heartbeats = Effect.gen(function* () { |
| 15 | const dataset = yield* Monitoring; |
| 16 | return yield* GCP.BigQuery.Table("Heartbeats", { |
| 17 | datasetId: dataset.datasetId, |
| 18 | tableId: "heartbeats", |
| 19 | schema: [ |
| 20 | { name: "kind", type: "STRING", mode: "REQUIRED" }, |
| 21 | { name: "jobName", type: "STRING", mode: "REQUIRED" }, |
| 22 | { name: "scheduleTime", type: "TIMESTAMP", mode: "REQUIRED" }, |
| 23 | { name: "receivedAt", type: "TIMESTAMP", mode: "REQUIRED" }, |
| 24 | { name: "value", type: "INTEGER", mode: "REQUIRED" }, |
| 25 | ], |
| 26 | }); |
| 27 | }); |
| 28 | |
| 29 | /** The row both schedules write. */ |
| 30 | export type HeartbeatRow = { |
| 31 | kind: "heartbeat" | "daily"; |
| 32 | jobName: string; |
| 33 | scheduleTime: Date; |
| 34 | receivedAt: Date; |
| 35 | value: number; |
| 36 | }; |