Documentation
¶
Index ¶
- Constants
- Variables
- func AddGlobalMiddleware(mw tasker.JobMiddleware)
- func Cancel(ctx context.Context, id tasker.JobID) (*tasker.JobRow, error)
- func Chain(ctx context.Context, jobs []tasker.Job, opts ...tasker.DispatchOpt) ([]*tasker.JobRow, error)
- func Dispatch(ctx context.Context, job tasker.Job, opts ...tasker.DispatchOpt) (*tasker.JobRow, error)
- func DispatchBatch(ctx context.Context, jobs []tasker.Job, opts ...tasker.DispatchOpt) ([]*tasker.JobRow, error)
- func GetJob(ctx context.Context, id tasker.JobID) (*tasker.JobRow, error)
- func RegisterJob(name string, factory tasker.JobFactory)
- func Retry(ctx context.Context, id tasker.JobID) (*tasker.JobRow, error)
- func ScheduleCommand(a app.App) *cobra.Command
- func Scheduler(a app.App) *scheduler.Scheduler
- type Config
- type Provider
Constants ¶
const ConfigStub = `` /* 1664-byte string literal not displayed */
const TagConfig = "queue-config"
TagConfig is what `lemmego publish --tags` selects this module's configuration on.
Variables ¶
var ErrNotInitialized = errors.New("queue: provider is not initialized")
Functions ¶
func AddGlobalMiddleware ¶
func AddGlobalMiddleware(mw tasker.JobMiddleware)
func DispatchBatch ¶
func RegisterJob ¶
func RegisterJob(name string, factory tasker.JobFactory)
func ScheduleCommand ¶ added in v0.3.0
ScheduleCommand runs the scheduler in the foreground.
One process, deliberately. tasker's scheduler has no leader election, so two of these dispatch every job twice. Run it as a single replica; for jobs where a double dispatch would be harmful anyway — a weekly rollup, an email — take a cache lock inside the job as well, because "exactly one process" is a promise a deployment makes and occasionally breaks.
func Scheduler ¶ added in v0.3.0
Scheduler returns the recurring-job scheduler, or nil if none was configured.
It is registered in the container whenever Provider.Schedule is set, so a handler or a command can inspect what is scheduled — List() is the honest answer to "what runs on a timer here", which is otherwise a grep.
Types ¶
type Config ¶
type Config struct {
Driver string
DSN string
DriverName string
TablePrefix string
RoutePrefix string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
RedisAddr string
RedisPass string
RedisDB int
RedisPoolSize int
RedisPrefix string
DefaultQueue string
DefaultMaxAttempts int
Workers map[string]int
EnableAutoscale bool
HeartbeatInterval int
RequeueInterval int
RequeueTimeout int
PruneInterval int
PruneAfterHours int
// contains filtered or unexported fields
}
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) ApplyOverrides ¶
ApplyOverrides applies every present key, including false and zero values.
type Provider ¶ added in v0.1.1
type Provider struct {
Config *Config
// DashboardAuth decides whether a request may use the management
// dashboard. Return true to let it through, false to answer 401.
//
// The dashboard can retry, cancel and delete jobs, so it stays closed
// until this is set: leaving it nil is not "no authentication", it is
// "no access". That is deliberate — the failure mode of the opposite
// default is a public button that clears somebody's queue.
//
// It takes an app.Context rather than a user, because "may this person
// use it" is a question about the request, and the answer usually needs
// the application's own user type:
//
// DashboardAuth: func(c app.Context) bool {
// if err := auth.Check(c); err != nil {
// return false
// }
// user, ok := auth.UserAs[*models.User](c)
// return ok && slices.Contains(admins, user.Email)
// },
//
// Call auth.Check yourself, and call it first. The dashboard is mounted
// as a raw http.Handler, so none of the router's middleware runs for it
// and nothing has looked at the request's cookie by the time this is
// called. Omit it and the user is always absent, so the answer is always
// no — an honest failure, but a puzzling one.
//
// Check resolves a session cookie and a bearer token alike, so one rule
// covers both. Nothing stops a check that ignores users entirely — a
// shared secret header, an IP allowlist — which is why this is a
// predicate over the request and not over a user interface.
DashboardAuth func(c app.Context) bool
// Schedule returns the jobs this application runs on a timer.
//
// Registering them is all this does. Nothing is started, because a
// scheduler started wherever it was constructed would run in every web
// process and every worker, and an hourly job would fire once per
// instance — invisibly, from inside any one of them. Start it with
// `lemmego run tasker:schedule`, as exactly one process.
//
// Schedule: func(a app.App) []scheduler.ScheduledJob {
// return []scheduler.ScheduledJob{
// {ID: "weekly-rollup", Schedule: "5 0 * * 1", Job: &jobs.RollWeek{}},
// }
// }
//
// A malformed cron expression fails startup rather than producing a job
// that never runs.
Schedule func(a app.App) []scheduler.ScheduledJob
// contains filtered or unexported fields
}
func (*Provider) AddCommands ¶ added in v0.1.1
func (*Provider) AddPublishables ¶ added in v0.1.1
func (p *Provider) AddPublishables() []*app.Publishable
func (*Provider) AddRoutes ¶ added in v0.1.1
func (p *Provider) AddRoutes() app.RouteCallback