job.ts
This file
Path
apps/sandbox/src/job.ts
66 lines · 2.5 KiB · TypeScript
Last changed by
Merge observability into mainoscabrielbefore adoption1985111
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge observability into mainoscabrielbefore adoption1985111
lines 1–3why, one step back1import { withInvocation } from "@repo/telemetry/spans";2import type { InvocationIds } from "@repo/telemetry/spans";3import type { TelemetryOptions } from "@repo/telemetry/telemetry";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 4why, one step back4import { Effect, Schema } from "effect";Merge observability into mainoscabrielbefore adoption1985111
line 5why, one step back5import type { Exit, Layer, Redacted } from "effect";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 6why, one step back6Merge observability into mainoscabrielbefore adoption1985111
lines 7–32why, one step back7import { jobTelemetry } from "./telemetry.ts";89/** A job the platform sends: its wire, its reply and what it shows of itself. */10export interface Job<W, WI, A, E, X> {11 /** Its span: Workers do not trace a container, so this is the trace's view of it. */12 readonly name: string;13 readonly wire: Schema.Codec<W, WI>;14 readonly exit: Schema.Codec<Exit.Exit<A, E>, X>;15 /** What Issues shows beside it: ids only, never a repo or a path. */16 readonly ids: (job: W) => InvocationIds;17 /** The tokens it carries, which nothing it logs or traces may. */18 readonly tokens: (job: W) => readonly Redacted.Redacted[];19 /** What its spans keep of a defect: its name alone where sealed files are near. */20 readonly defects: NonNullable<TelemetryOptions["defects"]>;21}2223/** The telemetry a job runs with, given its tokens and what its spans keep of a defect. */24export type JobTelemetry = (25 tokens: readonly Redacted.Redacted[],26 defects: NonNullable<TelemetryOptions["defects"]>27) => Layer.Layer<never>;2829// A defect is no report of the sandbox's own: it crosses in the job's Exit,30// and the platform reports it there, once, by its name and frames, with the31// job's tokens scrubbed.32export const answered =Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 33why, one step back33 <W, WI, A, E, X>(Merge observability into mainoscabrielbefore adoption1985111
lines 34–36why, one step back34 job: Job<W, WI, A, E, X>,35 run: (wire: W) => Effect.Effect<A, E>,36 telemetry: JobTelemetry = jobTelemetryMerge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 37why, one step back37 ) =>Merge observability into mainoscabrielbefore adoption1985111
lines 38–45why, one step back38 (encoded: WI): Effect.Effect<X> =>39 Schema.decodeEffect(job.wire)(encoded).pipe(40 Effect.orDie,41 Effect.flatMap((decoded) =>42 run(decoded).pipe(43 Effect.withSpan(job.name),44 withInvocation(job.ids(decoded)),45 Effect.provide(telemetry(job.tokens(decoded), job.defects))Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
line 46why, one step back46 )Merge observability into mainoscabrielbefore adoption1985111
lines 47–50why, one step back47 ),48 Effect.exit,49 Effect.flatMap((outcome) =>50 Effect.orDie(Schema.encodeEffect(job.exit)(outcome))Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 51–52why, one step back51 )52 );Merge observability into mainoscabrielbefore adoption1985111
lines 53–60why, one step back5354export const answerJob =55 <W, WI, A, E, X>(56 job: Job<W, WI, A, E, X>,57 run: (wire: W) => Effect.Effect<A, E>58 ) =>59 (encoded: WI): Promise<X> =>60 Effect.runPromise(answered(job, run)(encoded));Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 61–66why, one step back6162export const notBuilt = <E>(job: string, blocked: E) =>63 Effect.logWarning("sandbox job not built").pipe(64 Effect.annotateLogs({ job, reason: "not built" }),65 Effect.andThen(Effect.fail(blocked))66 );