Documentation
¶
Overview ¶
Package embeddedtemporal runs a Temporal server inside the current process so a single Go binary can host durable workflows with no external infrastructure. It supports two modes:
- Ephemeral (default): an in-memory server for demos, tests, and blog-sized examples. State is lost when the process exits.
- Persistent (WithDatabaseFile): a file-backed SQLite server for single-user desktop durable-agent apps. Start, do work, stop, and restart later with workflow state intact. The on-disk schema is migrated forward on startup (see schema.go), so the database survives go.temporal.io/server upgrades.
The server is built on the vendored LiteServer (internal/litekit). The convenience helpers never close a door: Client, HostPort, and Namespace expose the underlying primitives so callers can build any client or worker the Temporal SDK allows.
Neither mode is for production: persistent mode assumes a single server process owns the database file (enforced by a lock, see lock.go).
Index ¶
Constants ¶
const DefaultNamespace = "default"
DefaultNamespace is the namespace registered when WithNamespace is not set. A stable default lets a restarted persistent app address the same namespace.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*config)
Option customizes an embedded server.
func WithClientOptions ¶
WithClientOptions sets base client.Options for the client returned by Client. HostPort and Namespace are managed by the server and are overridden.
func WithDatabaseFile ¶
WithDatabaseFile switches Start to persistent mode, storing all state in the SQLite file at path. The file and its parent directory are created if needed, and the schema is migrated forward on startup. Without this option the server is ephemeral (in-memory).
func WithNamespace ¶
WithNamespace registers and uses namespace instead of DefaultNamespace.
func WithWorkerOptions ¶
WithWorkerOptions sets base worker.Options used by StartWorker.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a running in-process Temporal server. Construct it with Start and release it with Close. The zero value is not usable.
func Start ¶
Start launches an in-process Temporal server and returns it ready to use. The caller owns the returned Server and must call Close to release resources.
srv, err := embeddedtemporal.Start(embeddedtemporal.WithDatabaseFile(path))
if err != nil {
return err
}
defer srv.Close()
func (*Server) Client ¶
Client returns a Temporal client connected to the embedded server's namespace. The client is closed by Close; do not close it yourself.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the embedded server, its workers, and its client, and releases the persistent-mode database lock. It is safe to call once.
func (*Server) HostPort ¶
HostPort returns the frontend host:port of the embedded server, for callers that need to dial it from another process or configure external tooling.
func (*Server) StartWorker ¶
func (s *Server) StartWorker(taskQueue string, register func(worker.Registry)) (worker.Worker, error)
StartWorker registers a worker on taskQueue and starts polling. The register callback receives the native worker.Registry, so generated Register functions drop straight in:
srv.StartWorker(myapp.DefaultTaskQueue, func(r worker.Registry) {
myapp.Register(r, &myapp.Activities{...})
})
The returned worker is stopped by Close. For full control over worker construction, use worker.New(srv.Client(), ...) directly instead.