@colony2/jobdb

中文文档
0.0.81发布于 2026/11/10Apache-2.0ES Module构建来源已验证近 30 天下载 9024

jobdb job system

原始使用文档
文档目录13 节
  1. Named cells and the hard break
  2. Installation
  3. Container Image
  4. Quick Start
  5. Backend Options
  6. SQLite
  7. Toy
  8. Postgres
  9. Runtime API
  10. Tenant Configuration
  11. Go Workflow Workers
  12. Development
  13. Optional canonical lease events

jobdb

jobdb is a runtime server for durable jobs. The installed jobdb command serves the JobDB runtime REST API over HTTP using one of the available storage backends.

Use the server when you want a standalone runtime process that workers and other clients can talk to over the remote runtime protocol.

Named cells and the hard break

Jobs require a cell name. A cell has a stable generated ID, a unique tenant-local name, a Git repository, description, and arbitrary JSON metadata. All names can change; old names remain aliases. Repo and metadata updates use PATCH with an ETag. Cells are retired, never deleted.

The earlier named-cell transition has a separate storage and client upgrade boundary for pre-cell deployments. Lease events preserve format-11 storage and require no coordinated client upgrade. Explicitly create cells against the JobDB API URL before submitting jobs:

jobdb cell create --name root --tenant acme --repo github.com/acme/root --url http://localhost:9047
jobdb cell create --name payments --tenant acme --repo github.com/acme/payments --url http://localhost:9047

Submission never creates a cell. cellRepo optionally asserts an existing cell's repository; later submissions can use its name alone. root is an ordinary name with no special privileges or rename restrictions. Job IDs remain tenant-wide. See the cell specification for the HTTP contract, authorization hooks, and integration guides.

Installation

Install the CLI with npm:

npm install -g @colony2/jobdb

Verify the command is available:

jobdb --help

Container Image

The Postgres container is released from the pgjobdb repository as ghcr.io/colony-2/pgjobdb:<release-tag>.

Quick Start

Run the default SQLite-backed server:

jobdb --listen 127.0.0.1:9047 --db jobdb.db

This starts the runtime API at http://127.0.0.1:9047. SQLite is the default backend and persists runtime state in jobdb.db; large artifacts are stored in a blob bucket URL that defaults to a local blobfs:// directory at <db>.blobs.

The explicit SQLite subcommand is equivalent:

jobdb sqlite --listen 127.0.0.1:9047 --db jobdb.db

Stop the server with Ctrl-C or SIGTERM; the command shuts the HTTP server down before closing backend resources.

Backend Options

SQLite

SQLite is the default embedded durable backend.

jobdb sqlite \
  --listen 127.0.0.1:9047 \
  --db ./jobdb.db \
  --blob-store-uri 'file:///var/lib/jobdb/blobs'

Flags:

  • --db: SQLite database path. Defaults to jobdb.db.
  • --blob-store-uri: blob bucket URL for large artifacts. The jobdb executable includes Go CDK providers, so it supports file://, gs://, s3://, and azblob://; defaults to local blobfs:// at <db>.blobs.
  • --blob-dir: legacy directory shortcut for local large artifacts. Ignored when --blob-store-uri is set.
  • --sqlite-dsn: SQLite DSN. Overrides --db and JOBDB_SQLITE_DSN.
  • --listen: HTTP listen address. Defaults to 127.0.0.1:9047.

Environment:

  • JOBDB_SQLITE_DSN: SQLite DSN used when --sqlite-dsn is not set.

Toy

The toy backend is in-memory. It is useful for local experiments and tests, not for durable execution.

jobdb toy --listen 127.0.0.1:9047

Postgres

The base jobdb CLI provides SQLite and toy backends. The Postgres runtime, direct and serve commands, and container image are provided by pgjobdb. It composes JobDB's public runtime core with the typed Postgres scheduler.

Library embedders of runtime/sqlite only gets blobfs:// support by default. Import github.com/colony-2/jobdb/pkg/jobdb/blobstore/gocdk from executable/server code to enable Go CDK provider URI registration.

Library users can import github.com/colony-2/pgjobdb/pkg/pgjobdb/runtime for Postgres or import another runtime implementation. The public github.com/colony-2/jobdb/pkg/jobdb and runtime/core packages do not import pgjobdb.

References:

Runtime API

The server exposes the JobDB runtime REST API. The wire contract is documented in openapi/jobdb-runtime.yaml.

Go clients normally use the remote runtime adapter:

runtime, err := remoteruntime.New("http://127.0.0.1:9047", nil)

See pkg/jobdb/README.md for the Go runtime API, data types, and runtime package reference.

To recover a job blocked by repeated worker crashes, run jobdb jobs clear-crash-concern -t TENANT JOB_ID --reason 'worker issue fixed'. See clearing crash concern for CLI options, REST and Go examples, and recovery behavior.

Tenant Configuration

Every backend provides a tenant configuration store and public administration API. Set strings by default, or use --json (-j) for JSON values, through a running server:

jobdb config set codex_api_base_url -t tenant-a -f ./codex.url
printf '%s' '{"region":"eu-west-1","parallelism":4}' | jobdb config set build.defaults -t tenant-a -f - -j
jobdb config add build.defaults -t tenant-a -f ./defaults.json --json
jobdb config remove build.defaults -t tenant-a

String input preserves whitespace, including trailing newlines. Existing commands that supply JSON must now include --json (-j).

--url (-u) selects the server (default http://127.0.0.1:9047). Set JOBDB_BEARER_TOKEN if deployment authentication requires it. --if-match accepts a quoted ETag for conditional writes. Configuration is ordinary JSON application data; use the secrets API for credentials.

Go workers call ctx.GetConfiguration(context.Background()) on job or task contexts. The first successful read is cached for the live job attempt and shared by its tasks. Whole-job retries and resumptions start fresh. Secrets use the same scope, caching each requested name. See the cache lifecycle and migration guide and the configuration contract, including replay rules and the companion Postgres runtime upgrade.

For implementation examples, see the Go configuration guide. Postgres maintainers should follow the pgjobdb update guide.

Go Workflow Workers

Workflow workers are intentionally documented separately from the server. If you are writing job workers, task workers, or a process that runs worker loops, use the pkg/workflow package.

See pkg/workflow/README.md. To hand a claimed lease to another worker process without acquiring it again, see supplied-lease execution.

Development

The CLI source lives in cmd/jobdb. To run it directly from a checkout:

go run ./cmd/jobdb --listen 127.0.0.1:9047 --db jobdb.db

Run the full test suite:

go test ./...

Useful references:

See SQLite development secrets for tenant secret storage, CLI administration, and lease-scoped secret resolution.

Optional canonical lease events

SQLite and toy runtimes record lease events automatically with existing constructors and CLI invocations. Legacy implementations retain the same base interfaces; use jobdb.ListLeaseEvents(ctx, runtime, req) to query optional support and handle ErrLeaseEventsUnsupported. SQLite keeps base format 11 and installs the additive extension transactionally at startup, preserving existing data. Known format-12 databases are validated and normalized automatically. Pre-upgrade activity and historical writers leave partial history; no backfill is fabricated. See lease event compatibility and upgrades.

版本与发布记录

@colony2/jobdb 共发布 73 个版本,首次发布于 2026/06/23;过去 12 个月发布了 73 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.81latest2026/11/10今天
0.0.802026/11/10今天
0.0.792026/11/091 天前
0.0.782026/11/091 天前
0.0.772026/11/091 天前
0.0.762026/11/082 天前

关于 @colony2/jobdb 的常见问题

@colony2/jobdb 是什么?

jobdb job system

如何安装 @colony2/jobdb?

在项目目录运行 npm install @colony2/jobdb,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 jobdb,可以用 npx jobdb 直接运行。

@colony2/jobdb 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/colony2__jobdb 是否存在。

@colony2/jobdb 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@colony2/jobdb 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@colony2/jobdb 可以商用吗?

@colony2/jobdb 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@colony2/jobdb 的下载量有多少?

根据 npm 官方下载统计,@colony2/jobdb 在 2026/10/11 – 2026/11/09 这 30 天内被下载 9,024 次,日均约 301 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@colony2/jobdb 还在维护吗?

最新版本 0.0.81 发布于 2026/11/10(今天);至今共发布 73 个版本,其中过去 12 个月发布了 73 个;首次发布于 2026/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。