embeddedtemporal

package
v0.0.0-...-afad831 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

View Source
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

func WithClientOptions(options client.Options) Option

WithClientOptions sets base client.Options for the client returned by Client. HostPort and Namespace are managed by the server and are overridden.

func WithDatabaseFile

func WithDatabaseFile(path string) Option

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

func WithNamespace(namespace string) Option

WithNamespace registers and uses namespace instead of DefaultNamespace.

func WithWorkerOptions

func WithWorkerOptions(options worker.Options) Option

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

func Start(opts ...Option) (*Server, error)

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

func (s *Server) Client() client.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

func (s *Server) HostPort() string

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) Namespace

func (s *Server) Namespace() string

Namespace returns the namespace registered on the embedded server.

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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL