Skip to content

Deploying to a Worker

Declare a Worker release for the Scraper, add it to the instance's catalog and deploy it with the scwrap CLI.

To run on an instance, a Scraper needs a Release: one deployable build that names the Definition, picks an Implementation and provides its Capabilities.

quotes only needs fetch, so it becomes a Worker release that runs inside the instance's Worker.

Declare the Release ​

Releases live in your repository's releases package, one module each, apart from the Scraper's package.

First add the Scraper and the deployment SDK to releases/package.json and run pnpm install:

json
"dependencies": {
  "@scwrap/deploy": "0.5.0",
  "@scwrap/quotes": "workspace:*",
  "effect": "4.2.0"
}

Then declare the Release.

Example (releases/src/quotes.ts)

ts
import { Deployment } from "@scwrap/deploy";
import { Quotes, QuotesApiLive } from "@scwrap/quotes";
import { FetchHttpClient } from "effect/http";

export default Deployment.worker({
  implementation: QuotesApiLive,
  module: import.meta.url,
  scraper: Quotes,
  services: FetchHttpClient.layer,
});

A Release is the default export of its own module.

FieldMeaning
scraperThe Definition. Its ID, quotes, becomes the Release's ID on the instance.
implementationThe Implementation this Release runs.
servicesA Layer that provides every Capability the Implementation needs.
moduleAlways import.meta.url: where the bundler finds this Release.

A Release also has a revision, a label that defaults to v1. The digest of the built code, not the label, identifies a build.

A missing Capability does not compile ​

An instance supplies no Capabilities. Whatever the Implementation needs, services must provide.

QuotesApiLive needs an HttpClient, and FetchHttpClient.layer provides one. If you pass a Layer that does not, the compiler stops you at the implementation line:

text
Type 'HttpClient' is not assignable to type 'never'.
Missing 'HttpClient' in the expected Layer context. effect(missingLayerContext)

You find out at your desk, not in production.

Add it to the catalog ​

Your repository's Releases are the entries of one array, the default export of the catalog module.

Example (releases/src/catalog.ts)

ts
import QuotesRelease from "./quotes.ts";

const catalog = [QuotesRelease];

export default catalog;

A Scraper that is not in this array is not deployed. pnpm scwrap reads releases/src/catalog.ts unless SCWRAP_CATALOG names another module.

Deploy it ​

WARNING

Deploying changes a live instance. Know which instance SCWRAP_INSTANCE_URL names before you run it.

The scwrap CLI sends the selected Releases' source to the instance, which typechecks, builds and deploys them. It reads the instance from two environment variables:

VariableValue
SCWRAP_INSTANCE_URLYour instance's HTTPS origin, such as https://scwrap.example.com.
SCWRAP_INSTANCE_DEPLOYER_TOKENThe instance's deployer token. Keep it in the environment, never in a command argument.

Build the packages the catalog imports, then deploy quotes:

sh
pnpm --filter '{./releases}^...' build

pnpm scwrap deploy quotes

The CLI prints where it keeps this deploy's journal, then one JSON line per Release:

text
Journal: /home/you/.local/state/scwrap/journals/2026-11-22T16-21-07-512Z-3f9a1c2e
json
{"buildId":"…","status":"passed","scraper":{"id":"quotes","revision":"v1"},"deployment":{"deploymentId":"build-…","generation":"…","status":"active"}}

active means the instance now runs this Release. A build that fails prints the TypeScript diagnostics instead, and nothing changes.

If the status is pending ​

pending means the upload happened but the instance has not confirmed the new version yet. It is not a failure, and it is not a success.

Run retry with the journal the deploy printed until the Release is active:

sh
pnpm scwrap retry --journal "$HOME/.local/state/scwrap/journals/2026-11-22T16-21-07-512Z-3f9a1c2e"

The journal is a directory the CLI creates outside the repository. It holds the exact build requests it sent, so a retry repeats the same build and deployment even after you changed the source.

Check what is installed ​

sh
pnpm scwrap deployments

This prints the instance's generation and every installed Release with its id, revision and digest.

Deploying from CI ​

Your repository's CI can deploy the same way after its tests pass, with the instance URL and the deployer token as secrets:

sh
pnpm scwrap deploy --changed --journal "$journal"

--changed sends the whole catalog; the instance deploys only the Releases whose build differs from what it runs, and never removes one. Releases that other repositories deployed to the same instance stay installed.

What the instance now does ​

For every Run of quotes, the instance's Worker:

  1. Checks the input against QuotesQuery.
  2. Runs QuotesApiLive with fetch.
  3. Checks each quote against Quote and writes it to R2.
  4. Writes the result record: completed or failed, the item count and the Release's digest.

Next ​

Calling your Scraper runs the deployed Scraper and reads its items.

For the details behind this page, see Releases and The scwrap CLI.