job

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 8 Imported by: 0

README

fx/modules/bootstrap/job

fx module that runs the provided job.Handler once and stops the app, so the process exits when the job is done:

boost.Start()
fxfact.NewApp(
	fx.Provide(func(a *Auditor) job.Handler { return a.Run }),
	jobfx.Module(),
).Run()

builder generates this for @Job.

Lifecycle

  • OnStart runs the handler in a goroutine, with a context the stop cancels, so fx.New returns.
  • When the handler returns, the module calls Shutdowner.Shutdown with exit code 0 on nil; an error is logged at ERROR (job failed: <error>) and exits 1.
  • OnStop (SIGTERM, or another hook stopping the app first) cancels the handler's context and waits for it to return, up to the stop timeout (fx's 15s by default). Its error fails the stop, so the app exits 1, and nil lets it exit 0; a handler still running at the timeout fails the stop with the deadline. A job cut short never reports success unless it says so.

Module() returns an empty option after the first call.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module() fx.Option

Module fx module that runs the job.Handler the app provides once. It runs from the app's OnStart and shuts the app down when it returns: exit code 0 on nil, 1 on an error, logged at ERROR. OnStop (SIGTERM) cancels its context and waits for it until the stop timeout; a handler that had not finished fails the stop, so the app exits 1.

Types

This section is empty.

Jump to

Keyboard shortcuts

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