Documentation
¶
Overview ¶
Package job defines the public contract every background job module must implement. Jobs are stateless top-level RunFuncs — one call to app.RegisterJob binds a Meta, a typed Config value, and a RunFunc. The RunFunc receives a context.Context that carries a *Ctx (via FromContext) so Run can read its own runtime-editable config without any extra plumbing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateJobs ¶
ValidateJobs is called by wick at boot. It checks that each Module's Meta has the minimum required fields (Key, Name, Icon), that Run is non-nil, and that no two jobs share the same Key. A non-nil error means the process should refuse to start.
Types ¶
type Ctx ¶
type Ctx struct {
// contains filtered or unexported fields
}
Ctx is the per-run handle wick passes to a job through context. It carries the owning job's Key and a view onto the configs service so Run() can read its own runtime-editable config without re-plumbing the service down from main.
Construction is internal to wick — jobs receive a ready-made Ctx via job.FromContext(ctx) inside Run.
func FromContext ¶
FromContext returns the Ctx attached to ctx, or a no-op Ctx when none is present (e.g. unit tests that call Run directly with a bare context). A no-op Ctx returns "" for every Cfg read, which matches the behavior of a tool that declares no configs.
func NewCtx ¶
NewCtx is used by the manager package to build a Ctx before calling Run. Downstream code should never call this — read the existing Ctx with FromContext instead.
func (*Ctx) Cfg ¶
Cfg returns the current value of a config field declared by this job. Scoped to the active job's Key — reading another owner's config requires CfgOf. Returns "" when the key is not declared or the config service is unavailable.
func (*Ctx) CfgBool ¶
CfgBool returns c.Cfg(key) parsed as bool. "true"/"1"/"yes"/"on" (case-insensitive) count as true; anything else is false.
type Meta ¶
type Meta struct {
Key string
Name string
Description string
Icon string
DefaultCron string
// DefaultTags works the same as tool.Tool.DefaultTags — seeded on
// startup, linked to the job's path, and used for tag-based access
// control in the admin UI.
DefaultTags []tool.DefaultTag
// AutoEnable forces Job.Enabled = true on every Bootstrap. Intended
// for built-in maintenance jobs that ship pre-enabled and have no
// user-facing toggle (typically combined with DefaultTags carrying
// the System tag so the row is hidden from non-admin manager UI).
// Admin-managed jobs leave this false — admins enable from the
// /manager/jobs UI.
AutoEnable bool
}
Meta holds the static metadata for a job instance. Downstream code passes one Meta per app.RegisterJob call — duplicating a module with a different Key + Meta registers a second scheduled instance backed by the same RunFunc.
type Module ¶
Module is the internal, fully-resolved registration record wick keeps for every job. It is produced by app.RegisterJob — the Meta, any configs reflected from the paired typed struct, and the RunFunc itself. Downstream code does not construct Module directly.
type RunFunc ¶
RunFunc is the job-side run signature. It executes the job and returns a markdown-formatted result string. An empty string means "no output to display". Errors should be returned via the error value, not embedded in the result.
ctx carries a *Ctx (via FromContext) so Run can read this instance's runtime config, e.g. job.FromContext(ctx).Cfg("endpoint"). When the job needs process-wide state (a DB handle, an HTTP client, a cache), wrap RunFunc in a factory: func NewRun(db *sql.DB) job.RunFunc { ... }.