Skip to content
GitHub

Configuration

Config section key: tasks — loaded from tasks: in application.yaml or via LEX_TASKS__* environment variables.

application.yaml
tasks:
enabled: true
env: production
backend:
type: redis
redis_url: "${REDIS_URL}"
queue_name: orders
worker:
worker_count: 8
poll_interval: 0.05
default_timeout: 300
enforce_timeout: true
scheduler:
enabled: true
timezone: UTC
rate_limit:
enabled: true
rate: 1000
per: 1.0
retry:
max_retries: 5
min_delay: 1.0
max_delay: 300.0
backends:
- name: urgent
primary: true
type: redis
redis_url: "${REDIS_URL}"
- name: batch
type: rabbitmq
amqp_url: "${AMQP_URL}"

KeyTypeDefaultEnv VarDescription
namestr"tasks"LEX_TASKS__NAMEConfiguration name
enabledboolTrueLEX_TASKS__ENABLEDWhether tasks module is enabled
envstr | NoneNoneLEX_TASKS__ENVEnvironment label (development/staging/production)
backendTaskBackendConfig{}(prefix)Task queue backend config
workerTaskWorkerConfig{}(prefix)Worker settings
schedulerTaskSchedulerConfig{}(prefix)Scheduler settings
retryRetryConfig{}(prefix)Retry policy
rate_limitTaskRateLimitConfig{}(prefix)Rate limiting
timeoutTaskTimeoutConfig{}(prefix)Timeout settings
extradict[str, Any]{}LEX_TASKS__EXTRA__*Extra arbitrary config
backendslist[NamedTaskConfig][](list)Named multi-backend queues

KeyTypeDefaultEnv VarDescription
typestr"memory"LEX_TASKS__BACKEND__TYPEBackend type: memory, redis, rabbitmq, postgres
redis_urlSecretStr"redis://localhost:6379"LEX_TASKS__BACKEND__REDIS_URLRedis connection URL
amqp_urlSecretStr"amqp://localhost:5672/"LEX_TASKS__BACKEND__AMQP_URLAMQP connection URL
postgres_dsnSecretStr | NoneNoneLEX_TASKS__BACKEND__POSTGRES_DSNPostgres DSN (for type: postgres)
queue_namestr"tasks"LEX_TASKS__BACKEND__QUEUE_NAMEQueue name

KeyTypeDefaultEnv VarDescription
worker_countint1LEX_TASKS__WORKER__WORKER_COUNTNumber of worker instances
max_concurrent_tasksint10LEX_TASKS__WORKER__MAX_CONCURRENT_TASKSMax concurrent tasks per worker
poll_intervalfloat0.1LEX_TASKS__WORKER__POLL_INTERVALQueue poll interval (seconds)
shutdown_timeoutfloat30.0LEX_TASKS__WORKER__SHUTDOWN_TIMEOUTGraceful shutdown timeout (seconds)
default_timeoutfloat300.0LEX_TASKS__WORKER__DEFAULT_TIMEOUTDefault task timeout (seconds)
max_timeoutfloat3600.0LEX_TASKS__WORKER__MAX_TIMEOUTMaximum allowed timeout (seconds)
enforce_timeoutboolTrueLEX_TASKS__WORKER__ENFORCE_TIMEOUTEnforce timeouts on all tasks

KeyTypeDefaultEnv VarDescription
enabledboolTrueLEX_TASKS__SCHEDULER__ENABLEDEnable job scheduling
check_intervalfloat1.0LEX_TASKS__SCHEDULER__CHECK_INTERVALSchedule check interval (seconds)
timezonestr"UTC"LEX_TASKS__SCHEDULER__TIMEZONETimezone for cron expressions

KeyTypeDefaultEnv VarDescription
enabledboolFalseLEX_TASKS__RATE_LIMIT__ENABLEDEnable rate limiting
rateint100LEX_TASKS__RATE_LIMIT__RATETasks allowed per time period
perfloat1.0LEX_TASKS__RATE_LIMIT__PERTime period (seconds)
burstint | NoneNoneLEX_TASKS__RATE_LIMIT__BURSTMax burst size

KeyTypeDefaultEnv VarDescription
default_timeoutfloat300.0LEX_TASKS__TIMEOUT__DEFAULT_TIMEOUTDefault task timeout
max_timeoutfloat3600.0LEX_TASKS__TIMEOUT__MAX_TIMEOUTMaximum allowed timeout
enforce_timeoutboolTrueLEX_TASKS__TIMEOUT__ENFORCE_TIMEOUTEnforce timeouts

Used in TaskConfig.backends for multi-backend queues.

KeyTypeDefaultDescription
namestr(required)Unique backend name for Named() DI resolution
primaryboolFalseAlso register under unnamed TaskQueueProtocol
typestr"memory"Backend type: memory, redis, rabbitmq, postgres
redis_urlSecretStr | NoneNoneRedis URL (when type: redis)
amqp_urlSecretStr | NoneNoneAMQP URL (when type: rabbitmq)
postgres_dsnSecretStr | NoneNonePostgres DSN (when type: postgres)
queue_namestr"tasks"Queue name for this backend

Nested keys use __ as delimiter:

Terminal window
# Set Redis backend URL
export LEX_TASKS__BACKEND__REDIS_URL="redis://prod-cluster:6379"
# Set worker count
export LEX_TASKS__WORKER__WORKER_COUNT=16
# Disable scheduler
export LEX_TASKS__SCHEDULER__ENABLED=false
# Set production environment
export LEX_TASKS__ENV=production