Hyperlinkv0.8.0-beta.28

QueueHyperlink

QueueHyperlink.queueControlSpecconstsrc/QueueHyperlink.ts:517
{
  status: Hyperlink.Marked<
    Hyperlink.Method<
      undefined,
      Schema.Struct<{
        readonly sizes: Schema.Struct<{
          readonly high: Schema.Number
          readonly normal: Schema.Number
          readonly low: Schema.Number
        }>
        readonly paused: Schema.Boolean
        readonly inFlight: Schema.Number
        readonly completed: Schema.Number
        readonly phase: Schema.Literals<
          readonly ["running", "draining", "off"]
        >
      }>,
      Schema.Never,
      true,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >,
    { readonly _tag: "ref" }
  >
  size: Hyperlink.Marked<
    Hyperlink.Method<
      undefined,
      Schema.Number,
      Schema.Never,
      true,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >,
    { readonly _tag: "ref" }
  >
  isEmpty: Hyperlink.Marked<
    Hyperlink.Method<
      undefined,
      Schema.Boolean,
      Schema.Never,
      true,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >,
    { readonly _tag: "ref" }
  >
  start: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  pause: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  resume: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & { description: string },
    Hyperlink.Derive
  >
  shutdown: Hyperlink.Method<
    undefined,
    Schema.Void,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & {
      description: string
      destructive: true
    },
    Hyperlink.Derive
  >
  clear: Hyperlink.Method<
    undefined,
    Schema.Number,
    Schema.Never,
    false,
    Hyperlink.MethodAnnotations & {
      description: string
      destructive: true
    },
    Hyperlink.Derive
  >
  metrics: {
    stream: Hyperlink.Method<
      undefined,
      Schema.Struct<{
        readonly windowStart: Schema.DateTimeUtc
        readonly windowEnd: Schema.DateTimeUtc
        readonly windowMillis: Schema.Number
        readonly enqueued: Schema.Number
        readonly started: Schema.Number
        readonly completed: Schema.Number
        readonly failed: Schema.Number
        readonly retried: Schema.Number
        readonly deadLettered: Schema.Number
        readonly dropped: Schema.Number
        readonly rateLimitExceeded: Schema.Number
        readonly inFlight: Schema.Number
        readonly throughputPerSec: Schema.Number
        readonly avgWaitMillis: Schema.Struct<{
          readonly high: Schema.optionalKey<Schema.Number>
          readonly normal: Schema.optionalKey<Schema.Number>
          readonly low: Schema.optionalKey<Schema.Number>
        }>
        readonly avgExecutionMillis: Schema.optionalKey<Schema.Number>
        readonly avgTotalMillis: Schema.optionalKey<Schema.Number>
      }>,
      Schema.Never,
      true,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >
    query: Hyperlink.Method<
      {
        limit: Schema.optionalKey<Schema.Number>
        since: Schema.optionalKey<Schema.DateTimeUtc>
        until: Schema.optionalKey<Schema.DateTimeUtc>
      },
      Schema.$Array<
        Schema.Struct<{
          readonly windowStart: Schema.DateTimeUtc
          readonly windowEnd: Schema.DateTimeUtc
          readonly windowMillis: Schema.Number
          readonly enqueued: Schema.Number
          readonly started: Schema.Number
          readonly completed: Schema.Number
          readonly failed: Schema.Number
          readonly retried: Schema.Number
          readonly deadLettered: Schema.Number
          readonly dropped: Schema.Number
          readonly rateLimitExceeded: Schema.Number
          readonly inFlight: Schema.Number
          readonly throughputPerSec: Schema.Number
          readonly avgWaitMillis: Schema.Struct<{
            readonly high: Schema.optionalKey<Schema.Number>
            readonly normal: Schema.optionalKey<Schema.Number>
            readonly low: Schema.optionalKey<Schema.Number>
          }>
          readonly avgExecutionMillis: Schema.optionalKey<Schema.Number>
          readonly avgTotalMillis: Schema.optionalKey<Schema.Number>
        }>
      >,
      Schema.Never,
      false,
      Hyperlink.MethodAnnotations & { description: string },
      Hyperlink.Derive
    >
  }
}

The queue control + observation contract: the fixed-schema verbs of a queue handle, shared by every queue instance. The data-plane (item-typed) verbs are added in a later slice. Mirrors the matching members of QueueHyperlink's QueueHandleApi.

wire schemas
export const queueControlSpec = {
  // ── live current state — one SubscriptionRef-backed source of truth ──
  // `status` is the whole snapshot; the scalars are `Stream.map` derivations of it (SSOT). All are
  // plain reads (`p.size`) and subscribable (`Hyperlink.changes(p, (s) => s.size)`).
  status: Hyperlink.ref(queueStatus).annotate({
    description:
      "Live current-state snapshot: per-priority sizes, paused, in-flight, completed, phase.",
  }),
  size: Hyperlink.ref(Schema.Number).annotate({
    description: "Total pending items across all priority levels.",
  }),
  isEmpty: Hyperlink.ref(Schema.Boolean).annotate({
    description: "Whether all priority queues are empty.",
  }),

  // ── lifecycle commands ──
  start: Hyperlink.effect(Schema.Void).annotate({
    description:
      "Fork the worker pool + lifecycle monitor (idempotent; no-op after shutdown).",
  }),
  pause: Hyperlink.effect(Schema.Void).annotate({
    description: "Pause processing; items can still be enqueued and accumulate.",
  }),
  resume: Hyperlink.effect(Schema.Void).annotate({
    description: "Resume processing after a pause.",
  }),
  shutdown: Hyperlink.effect(Schema.Void).annotate({
    description:
      "Permanently stop the queue (graceful): phase → draining, later enqueues dropped, " +
      "in-flight finishes, queued items drained or discarded per shutdownMode, then phase → off.",
    destructive: true,
  }),
  clear: Hyperlink.effect(Schema.Number).annotate({
    description:
      "Drain all pending items and reset the completed counter; returns the count cleared.",
    destructive: true,
  }),

  // ── observability — stream + query, paired by nesting ──
  metrics: {
    stream: Hyperlink.stream(queueMetrics).annotate({
      description:
        "Windowed metrics (per-window counts + throughput/latency) emitted once per window.",
    }),
    query: Hyperlink.effectFn(historyQuery, Schema.Array(queueMetrics)).annotate({
      description:
        "Past windowed metrics from the HistoryStore (newest `limit` within `since`/`until`); " +
        "empty unless a HistoryStore layer is provided.",
    }),
  },
};
Referenced by 1 symbols