Help us shape the future of Go! Take the 2026 Go Developer Survey

task

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package task is the application's asynq consumer: it registers the handler of every task type and runs them behind the trace middleware, with one failure log line per attempt and the retry policy of the scheduled tasks. The handlers live in the subpackages and only decode payloads and call the modules, which own the transactions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(mux *asynq.ServeMux, deps Dependencies)

RegisterHandlers binds every task type to its handler.

Types

type Dependencies

type Dependencies struct {
	Email        email.Dependencies
	SMS          sms.Dependencies
	Order        order.Dependencies
	EventBus     *eventbus.Bus
	Traffic      traffic.Dependencies
	Subscription moduleSubscription.Service
	// Tasks and System are the platform kernel's scheduled-task bookkeeping
	// and system settings.
	Tasks        repository.TaskRepo
	System       repository.SystemRepo
	ExchangeRate *billing.CurrencyRateCache
	// Bootstrapped fires once the runtime settings the handlers read are
	// loaded; the worker consumes only after it.
	Bootstrapped Readiness
}

Dependencies are what the task handlers are built from; the composition root provides them.

type Readiness added in v1.21.0

type Readiness interface {
	Done() <-chan struct{}
	Err() error
}

Readiness is the signal that the runtime settings the handlers read — the email and SMS platforms, the site name, the Telegram bot — are loaded: Done closes once the bootstrap finished, and Err reports its failure.

type Service

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

Service is the task worker the process runs next to the HTTP server and the scheduler.

func NewService

func NewService(redisOpt asynq.RedisConnOpt, deps Dependencies) *Service

NewService builds the task consumer on the queue's Redis connection; the composition root owns that connection's settings.

func (*Service) Start

func (m *Service) Start()

Start registers the handlers and consumes tasks until Stop. Consuming begins once the runtime settings the handlers read are loaded: a task run before that, such as an email queued during the start, would read empty settings and be dropped. The lifecycle group starts the services together, so the wait for the HTTP service's bootstrap happens here.

func (*Service) Stop

func (m *Service) Stop()

Stop stops pulling tasks, waits for the running handlers (up to asynq's shutdown timeout, eight seconds, after which an unfinished task goes back to its queue) and closes the queue connection. Start returns once it is done.

Directories

Path Synopsis
Package email holds the queue handlers that send email: single notifications (verification codes, expiry, traffic and maintenance notices, custom mail) and the marketing campaigns administrators run in batches, together with the workers that pace a campaign and record its progress.
Package email holds the queue handlers that send email: single notifications (verification codes, expiry, traffic and maintenance notices, custom mail) and the marketing campaigns administrators run in batches, together with the workers that pace a campaign and record its progress.
Package events hosts the queue shells of the domain-event bus: the publish pump moving outbox rows onto the asynq broker, and the delivery worker running subscribers.
Package events hosts the queue shells of the domain-event bus: the publish pump moving outbox rows onto the asynq broker, and the delivery worker running subscribers.
Package maintenance holds the queue handlers of the maintenance tasks: the quota grants administrators schedule and the daily exchange-rate refresh.
Package maintenance holds the queue handlers of the maintenance tasks: the quota grants administrators schedule and the daily exchange-rate refresh.
Package order holds the queue handlers of billing's order tasks: the activation of paid orders, the deferred close of unpaid ones, the paid and pending order reconcilers, the order-event outbox publication and retention, and the daily order report.
Package order holds the queue handlers of billing's order tasks: the activation of paid orders, the deferred close of unpaid ones, the paid and pending order reconcilers, the order-event outbox publication and retention, and the daily order report.
Package sms holds the queue handler that sends verification-code text messages through the configured provider and audits every attempt.
Package sms holds the queue handler that sends verification-code text messages through the configured provider and audits every attempt.
Package subscription holds the queue handlers of the scheduled subscription tasks: the lifecycle sweep and the pre-expiry reminder.
Package subscription holds the queue handlers of the scheduled subscription tasks: the lifecycle sweep and the pre-expiry reminder.
Package tasklock keeps two runs of one periodic task from overlapping, across replicas, with a Redis lock that only its owner may release or extend.
Package tasklock keeps two runs of one periodic task from overlapping, across replicas, with a Redis lock that only its owner may release or extend.
Package traffic holds the queue handlers of the traffic tasks: flushing the aggregated node traffic, the calendar traffic reset, the daily traffic statistics and the log retention.
Package traffic holds the queue handlers of the traffic tasks: flushing the aggregated node traffic, the calendar traffic reset, the daily traffic statistics and the log retention.

Jump to

Keyboard shortcuts

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