1import * as GCP from "alchemy/GCP";
2
3/**
4 * The queue. The API publishes one message per job; the worker pool's
5 * pull subscription (created for it by `GCP.Run.TopicPullEventSource`)
6 * holds each message until the worker acks it.
7 */
8export const Jobs = GCP.PubSub.Topic("Jobs", {});
9
10/**
11 * Job results, one document per job at `jobs/{id}`. The worker writes it
12 * when a job finishes; the API reads it to answer status polls.
13 */
14export const Results = GCP.Firestore.Database("Results", {
15 type: "FIRESTORE_NATIVE",
16});
17
18/** What the API publishes and the worker consumes. */
19export interface JobMessage {
20 id: string;
21 payload: string;
22 submittedAt: string;
23}
24
25/** The document the worker writes at `jobs/{id}`. */
26export interface JobResult {
27 status: "done";
28 /** Hex SHA-256 of the UTF-8 payload. */
29 sha256: string;
30 /** Whitespace-separated word count. */
31 words: number;
32 /** Payload length in characters. */
33 chars: number;
34 submittedAt: string;
35 completedAt: string;
36}
37
38/** Firestore path of a job's result document. */
39export const resultPath = (id: string) => `jobs/${id}`;