feat: library / embedded mode#4355
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
There was a problem hiding this comment.
Pull request overview
Adds a new in-process “embedded engine” mode via github.com/hatchet-dev/hatchet/embed, enabling Go applications to start a Hatchet engine (API + engine, no UI) inside the host process and obtain a configured Go SDK client. This advances the “library-only mode” effort from #3680 by providing a runnable embed package plus example binaries/scripts.
Changes:
- Introduces the new
embedpackage (startup, config options, keyset persistence, version resolution, fleet sizing) and anembed/examplemodule with engine/worker/trigger/basic examples. - Refactors advisory-lock hashing into
pkg/repository/sqlchelpers.AdvisoryLockKeyand reuses it frompkg/repository/task.go. - Adds a local dev runner script for embedded mode and minor workflow/task tweaks.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Taskfile.yaml | Makes version bump tasks fail-fast via set -e. |
| pkg/repository/task.go | Switches advisory-lock key hashing to shared helper. |
| pkg/repository/sqlchelpers/advisory.go | Adds shared advisory-lock key hashing helper. |
| hack/dev/embed/run.sh | Adds a local script to spin up multiple embedded engines/workers and trigger runs. |
| embed/version.go | Resolves Hatchet module version from build info for embedded startup. |
| embed/options.go | Adds embed configuration options and validation. |
| embed/keyset.go | Persists/loads local encryption keysets with an advisory lock. |
| embed/fleet.go | Checks active fleet size from DB to report “joining a fleet” status. |
| embed/example/worker/main.go | Example worker process for embedded engines. |
| embed/example/trigger/main.go | Example trigger tool to run workflows and summarize distribution. |
| embed/example/go.sum | Dependency lockfile for the standalone example module. |
| embed/example/go.mod | Standalone example module (with replace to local repo). |
| embed/example/engine/main.go | Example embedded engine launcher that writes connection info to a file. |
| embed/example/basic/main.go | Minimal single-process embedded engine + worker example. |
| embed/embed.go | Core embedded instance lifecycle (migrations, seeding, token minting, goroutine startup, SDK client). |
| cmd/hatchet-engine/main.go | Removes an outdated FIXME comment on Version. |
| .github/workflows/build.yml | Normalizes quoting for python-version values. |
| if err := os.Setenv("DATABASE_URL", cfg.postgresURL); err != nil { | ||
| return nil, fmt.Errorf("could not set DATABASE_URL: %w", err) | ||
| } | ||
| if cfg.adminEmail != "" { | ||
| _ = os.Setenv("ADMIN_EMAIL", cfg.adminEmail) | ||
| } | ||
| if cfg.adminPassword != "" { | ||
| _ = os.Setenv("ADMIN_PASSWORD", cfg.adminPassword) | ||
| } |
There was a problem hiding this comment.
I don't like this since I think it makes sense to simply override these env vars from within the embed engine since we have config level options. Open to what you think @abelanger5
| fleetStatus := "starting a new fleet" | ||
| if fleetSize > 0 { | ||
| fleetStatus = fmt.Sprintf("joining a fleet of %d engine(s)", fleetSize) | ||
| } | ||
| fmt.Fprintf(os.Stderr, "embed engine ready: api=%s grpc=%s | %s\n", apiURL, grpcBroadcast, fleetStatus) | ||
|
|
| fmt.Fprintf(os.Stderr, "embed engine ready: api=%s grpc=%s | %s\n", apiURL, grpcBroadcast, fleetStatus) | ||
|
|
There was a problem hiding this comment.
The idea here is to have a shared hatchet_embed.keyset DB table which keeps the autogenerated keyset information for such embedded instances and the user does not need to generate a keyset themselves.
When WithKeysets is provided we always use that instead of this path.
Can convert to required sqlc constructs once this approach is approved.
|
|
||
| const hatchetModulePath = "github.com/hatchet-dev/hatchet" | ||
|
|
||
| func resolveVersion() (string, error) { |
There was a problem hiding this comment.
Just resolving the library tagged version from the respective go.mod file
|
|
|
|
|
|
|
|
Description
Adds the ability to spawn an embedded Hatchet engine from a Go SDK client simply by providing a URL to a PostgreSQL DB.
This runs a full Hatchet engine (no UI) in-process with the Go binary it is embedded in.
Partially resolves #3680
Type of change
Checklist
Changes have been:
🤖 AI Disclosure