worker

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package worker is the library's own background goroutine group -- the mail drain and the token, limiter and signup sweeps -- as distinct from App.Lifecycle, which is the application's.

A Job is either a long-lived loop (Every == 0) or a periodic pass. A panicking job is recovered and logged rather than taking the process down with it. Stop waits for every job to return, and the HTTP server drains before the jobs do, so a mail queued by the last request in flight still goes out. See docs/design.md, FR-7.11 and FR-7.12.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group runs a set of jobs until their context is done.

func (*Group) Add

func (g *Group) Add(j Job)

Add registers a job. It must be called before Start.

func (*Group) Len

func (g *Group) Len() int

Len returns the number of registered jobs.

func (*Group) Start

func (g *Group) Start(ctx context.Context)

Start launches every registered job. It returns immediately.

func (*Group) Stop

func (g *Group) Stop(ctx context.Context)

Stop waits for every job to return, bounded by the caller's context so a job that will not finish cannot hang the shutdown. Cancelling the context the jobs were started with is what asks them to stop -- Stop only waits.

type Job

type Job struct {
	Name  string
	Every time.Duration
	Run   func(ctx context.Context) error
}

Job is one background task.

When Every is zero, Run is a long-lived loop: it is called once and must return when its context is done (the mail drain is one). Otherwise Run is a periodic pass, called once at start and then on every tick (the token sweep is one).

An error is logged, never fatal.

Jump to

Keyboard shortcuts

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