server

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 36 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server serves Blitz's API (proto/blitz/v1) over Connect: one process holding every workspace a user opens, each an engine.Workspace. Handlers translate between the protos and the engine; they hold no logic of their own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, l net.Listener, h http.Handler, grace time.Duration) error

Serve serves h on l (HTTP/1.1, and HTTP/2 without TLS for gRPC clients) until ctx is done, then stops accepting and waits up to grace for calls in progress.

Types

type Opener

type Opener func(ctx context.Context, dir string) (*engine.Workspace, error)

Opener opens the workspace in dir, an absolute directory. The server calls it once per workspace; each call must build its own configuration, since a workspace owns and changes it.

type Option

type Option func(*Server)

Option configures a Server.

func WithConfigDir

func WithConfigDir(dir string) Option

WithConfigDir is the settings directory the service loads from ("" for the usual one, ~/.blitz), as the --config flag.

func WithLogDir

func WithLogDir(dir string) Option

WithLogDir is the directory of the service's diagnostic log, which ListLogDays and ReadLog read ("": none).

func WithScheduler

func WithScheduler(c SchedulerConfig) Option

WithScheduler makes the server run enabled workers on their schedules (StartScheduler) and serve WorkerService.

func WithShutdown added in v0.4.0

func WithShutdown(stop func()) Option

WithShutdown is what Shutdown calls to stop the service; without it the service can't be stopped that way.

func WithVersion

func WithVersion(v string) Option

WithVersion is the version GetServiceInfo reports ("dev" otherwise).

type SchedulerConfig

type SchedulerConfig struct {
	// Store says which workers are enabled; the Opener must give each
	// workspace the same one (engine.Options.Workers).
	Store *workers.Store
	// Runs is where workspaces record finished runs (the same directory
	// engine.Workspace uses), for looking runs up by ID.
	Runs *workers.RunLog
	// MaxConcurrent is how many runs may go at once (at least 1).
	MaxConcurrent int
	// Rescan is how often workers are rescanned, to pick up new, edited
	// and removed WORKER.md files (0: a minute).
	Rescan time.Duration
}

SchedulerConfig configures the service's worker scheduler.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the open workspaces and serves the API.

func New

func New(open Opener, opts ...Option) *Server

New returns a server that opens workspaces with open.

func (*Server) Close

func (s *Server) Close() error

Close closes every workspace; none opens after it.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves every service.

func (*Server) IdleFor added in v0.3.1

func (s *Server) IdleFor() time.Duration

IdleFor is how long the service has had nothing to do: no request in flight, no turn running in any workspace and no background run going; 0 while it has.

func (*Server) StartScheduler

func (s *Server) StartScheduler(ctx context.Context)

StartScheduler runs workers on their schedules until ctx is done, which also stops the runs going then (as Close does). It does nothing without WithScheduler.

Jump to

Keyboard shortcuts

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