v1.2.1

Architecture

Last updated


This page shows go-scheduler's component layers and cross-cutting principles in a single overview diagram.

System Overview


graph TB
    App[Caller] --> Cron[cron scheduler]
    Cron --> Parser[Expression parser]
    Cron --> Heap[Task min-heap]
    Heap --> Loop[Event loop goroutine]
    Loop -->|no deps| Direct[Direct goroutine run]
    Loop -->|has deps| Queue[Wait queue]
    Queue --> Workers[Dependency worker pool]
    Workers --> Manager[dependManager]
    Direct --> State[Task state]
    Manager --> State
  1. graph TB
  2. App[Caller] --> Cron[cron scheduler]
  3. Cron --> Parser[Expression parser]
  4. Cron --> Heap[Task min-heap]
  5. Heap --> Loop[Event loop goroutine]
  6. Loop -->|no deps| Direct[Direct goroutine run]
  7. Loop -->|has deps| Queue[Wait queue]
  8. Queue --> Workers[Dependency worker pool]
  9. Workers --> Manager[dependManager]
  10. Direct --> State[Task state]
  11. Manager --> State

Layers


LayerComponentFilesResponsibility
Public interfacecroncore/instance.go, core/add.go, core/remove.go, core/task.goNew / Start / Stop / Add / Remove / RemoveAll / List
Parsingparsercore/schedule.goTurns a spec into scheduleResult (cron, descriptors) or delayScheduleResult (@every)
SchedulingtaskHeapcore/task.goMin-heap ordered by next; the event loop only waits on the top entry
Executioncron.runAftercore/instance.goTasks without dependencies: goroutine run, timeout, panic recovery
Dependenciesdepend, dependManagercore/depend.go, core/dependManager.goQueue (capacity 1024), worker pool, prerequisite polling, result updates

Cross-Cutting Principles


PrincipleImplementation
One event loop owns the heapAfter Start, add, remove, and clear go through the add / remove / removeAll channels; before Start the heap is modified directly
Per-task lockingEach task holds a sync.RWMutex; dependency checks read prerequisite state under a read lock
Dependent and plain tasks are splitcron.run runs directly or enqueues to the worker pool based on whether after is empty
Bounded worker countruntime.NumCPU() when greater than 2, otherwise 2
Shutdown does not interrupt actionsStop waits for the WaitGroup and workers; actions do not receive a context

Further Reading


中文