Skip to content

pardnchiu/go-scheduler

Repository files navigation

Note

This README was generated by SKILL, get the ZH version from here.

go-scheduler

pkg card codecov license version

Lightweight Go task scheduler with cron syntax, task dependency chains, and failure strategy control.

Table of Contents

Features

go get github.com/pardnchiu/go-scheduler · Documentation

Cron Scheduling with Live Dispatch

Supports standard five-field cron expressions and preset descriptors like @every and @daily. A min-heap sorts trigger times so the next due task is woken with minimal overhead. Tasks can be added or removed dynamically while the scheduler is running, with no restart required.

Task Dependency Chains with Failure Strategies

Tasks can declare dependencies on other tasks, and the scheduler automatically blocks execution until prerequisites complete. Two failure strategies are provided: Skip ignores the failure and proceeds, while Stop aborts the entire dependency chain. Each dependency accepts an independent timeout to prevent a single stalled task from blocking the whole schedule.

Concurrency-Safe Execution with Panic Recovery

Each task runs in its own goroutine, with mutex and channel coordination ensuring consistent state. Panics are automatically recovered so one failing task never crashes the scheduler. Context-based timeouts trigger an onDelay callback, giving callers a hook for cleanup logic.

Architecture

graph TB
    subgraph Scheduler
        C[Cron Engine]
        H[Min-Heap]
    end

    subgraph Dependencies
        DM[Depend Manager]
        W[Worker Pool]
    end

    C -->|schedule trigger| H
    H -->|due task| C
    C -->|has deps| DM
    C -->|no deps| G[Goroutine Exec]
    DM -->|check complete| W
    W -->|deps satisfied| G
    G -->|report result| DM
Loading

File Structure

go-scheduler/
├── instance.go          # Scheduler creation, start, stop, and task execution
├── add.go               # Task addition and argument parsing
├── remove.go            # Task removal
├── task.go              # Task listing and heap implementation
├── schedule.go          # Cron expression and descriptor parsing
├── type.go              # Type definitions and constants
├── depend.go            # Dependency worker pool and task execution
├── dependManager.go     # Dependency checking, waiting, and state updates
├── cron_test.go         # Unit tests and benchmarks
├── go.mod
└── LICENSE

License

This project is licensed under the MIT LICENSE.

Author

邱敬幃 Pardn Chiu

Stars

Star


©️ 2025 邱敬幃 Pardn Chiu

About

Scheduler with standard cron and task dependencies

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages