scheduler

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

README ΒΆ

⏰ Monitor Scheduler Promoter (internal/scheduler)

internal/scheduler manages periodic polling of active monitors from the database and dispatches check tasks to probe execution workers.


πŸ“¦ Key Exports

Scheduler Struct

Manages periodic background ticker loops:

  • Queries database for active targets (status != 'PAUSED').
  • Builds CheckPayload items (monitor_id, target_url).
  • Dispatches execution tasks to worker pools asynchronously.
Start(pollInterval time.Duration)

Boots background promoter loop at specified interval (default: 10s).

Stop()

Gracefully halts the promoter ticker loop and waits for active dispatches to settle.


πŸ§ͺ Testing & Verification

Automated Unit Test Suite (scheduler_test.go)

We use an isolated SQLite test database (test_scheduler.db) and mock HTTP server to test monitor check polling and dispatching:

Test Method Test Focus & Verification
TestSchedulerRunCheckCycle - Creates an active monitor record (status = 'UP') in an isolated database.
- Executes RunOnce(ctx) synchronously to trigger a promoter check cycle.
- Verifies that the scheduler selects active monitors, dispatches check payloads to WorkerEngine, and generates a PingLog entry.
Running Scheduler Unit Tests
go test -v ./internal/scheduler

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Scheduler ΒΆ

type Scheduler struct {
	DB           *gorm.DB
	WorkerEngine *worker.WorkerEngine
	Ticker       *time.Ticker
	StopChan     chan struct{}
	// contains filtered or unexported fields
}

Scheduler manages periodic monitor polling and probe task dispatching.

func NewScheduler ΒΆ

func NewScheduler(database *gorm.DB, engine *worker.WorkerEngine) *Scheduler

NewScheduler initializes a new monitor check scheduler.

func (*Scheduler) RunCheckCycle ΒΆ

func (s *Scheduler) RunCheckCycle()

RunCheckCycle queries active monitors from DB and dispatches probe tasks.

func (*Scheduler) RunOnce ΒΆ

func (s *Scheduler) RunOnce(ctx context.Context) error

RunOnce executes a single check cycle synchronously (useful for tests).

func (*Scheduler) Start ΒΆ

func (s *Scheduler) Start(pollInterval time.Duration)

Start boots the monitor promoter loop ticking every interval (default 10s).

func (*Scheduler) Stop ΒΆ

func (s *Scheduler) Stop()

Stop halts the scheduler promoter loop gracefully.

Jump to

Keyboard shortcuts

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