v1.1.3

Presets

Last updated


This page explains PresetConfig, how a preset sets a task's priority and base timeout, and what an undefined preset name resolves to.

PresetConfig


  1. type PresetConfig struct {
  2. Priority Priority
  3. Timeout time.Duration
  4. }

FieldZero ValueDescription
PriorityPriorityImmediateInitial priority for tasks using this preset
Timeout0When > 0, replaces Config.Timeout as this preset's base timeout

A preset name missing from the map (including "") resolves to the zero PresetConfig{}, which means PriorityImmediate plus the global base timeout.

Example


  1. q := core.New(&core.Config{
  2. Workers: 8,
  3. Size: 1024,
  4. Timeout: 30 * time.Second,
  5. Preset: map[string]core.PresetConfig{
  6. "payment": {Priority: core.PriorityHigh},
  7. "email": {Priority: core.PriorityNormal},
  8. "report": {Priority: core.PriorityLow, Timeout: 60 * time.Second},
  9. },
  10. })

PresetPriorityEffective TimeoutPromotion
paymentHigh30s ÷ 2 = 15sNone
emailNormal30sTo High after 60s waiting
reportLowmin(60s × 2, 120s) = 120sTo Normal after 30s waiting
"" or undefinedImmediatemax(30s ÷ 4, 15s) = 15sNone

Promotion thresholds read only Config.Timeout, never a preset's Timeout. The rules behind each column: Priority Levels, Timeout Derivation, Anti-Starvation Promotion.
中文