server

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 68 Imported by: 1 module, 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 RetryPings

func RetryPings(ctx context.Context, r *pings.Recorder, every time.Duration)

RetryPings sends the pings that failed every interval until ctx ends (AI-12): a ping that waited out an outage goes within the hour.

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.

func ServePlain

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

ServePlain serves h on l without TLS, HTTP/1.1 and HTTP/2 in cleartext (h2c), until ctx is done, as ServeTLS does: for a listener behind a front end that ends TLS itself (spec_053_enterprise EN-03). It's Serve, named for the network listener.

func ServeTLS

func ServeTLS(ctx context.Context, l net.Listener, h http.Handler, cfg *tls.Config, grace time.Duration) error

ServeTLS serves h on l over TLS with cfg (HTTP/2, and HTTP/1.1 for clients without it), as Serve does: the network listener of a service others reach (spec_053_enterprise EN-03).

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

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 WithUse

func WithUse(r *pings.Recorder) Option

WithUse counts the front ends' use with r, once a day each (spec_054_active_installs AI-02): nil, or without it, nothing is counted.

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, once those being opened are (they close themselves, seeing closed); none opens after it.

func (*Server) Handler

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

Handler serves every service.

func (*Server) IdleFor

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, no background run, eval run, health check or scheduled reflection going; 0 while it has.

func (*Server) OrgWorkspaceFor

func (s *Server) OrgWorkspaceFor(ctx context.Context, dir string) (id, readOnly string)

OrgWorkspaceFor is the organization's workspace at dir, asked as the workspace opens: its ID ("" when dir isn't one; each model call carries it, spec_053 EN-22), and why it's read-only ("" when it isn't): it's a clone the person is only a Viewer of (EN-60). When the service can't be reached it's what the service last said for dir (EN-37), else neither (a Viewer's push is refused there anyway).

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