scheduler

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package scheduler provides job scheduling and execution functionality for scanorama. It manages scheduled discovery and scanning jobs, handles job queuing, and coordinates the execution of network scans and host discovery operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscoveryJobConfig

type DiscoveryJobConfig struct {
	NetworkID   string `json:"network_id"` // UUID string stored by the API handler
	Network     string `json:"network"`    // CIDR — populated at runtime if empty
	Method      string `json:"method"`     // populated at runtime if empty
	DetectOS    bool   `json:"detect_os"`
	Timeout     int    `json:"timeout_seconds"`
	Concurrency int    `json:"concurrency"`
}

DiscoveryJobConfig represents discovery job configuration.

type ScanJobConfig

type ScanJobConfig struct {
	NetworkID     string   `json:"network_id"` // UUID string stored by the API handler
	LiveHostsOnly bool     `json:"live_hosts_only"`
	Networks      []string `json:"networks,omitempty"` // populated at runtime if nil
	ProfileID     string   `json:"profile_id,omitempty"`
	MaxAge        int      `json:"max_age_hours"`
	OSFamily      []string `json:"os_family,omitempty"`
}

ScanJobConfig represents scan job configuration.

type ScheduledJob

type ScheduledJob struct {
	ID      uuid.UUID
	CronID  cron.EntryID
	Config  *db.ScheduledJob
	LastRun time.Time
	NextRun time.Time
	Running bool
}

ScheduledJob represents a scheduled job wrapper.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler manages scheduled discovery and scanning jobs.

func NewScheduler

func NewScheduler(database *db.DB, discoveryEngine *discovery.Engine, profileManager *profiles.Manager) *Scheduler

NewScheduler creates a new job scheduler.

func (*Scheduler) AddDiscoveryJob

func (s *Scheduler) AddDiscoveryJob(ctx context.Context, name, cronExpr string, config DiscoveryJobConfig) error

AddDiscoveryJob adds a new scheduled discovery job.

func (*Scheduler) AddScanJob

func (s *Scheduler) AddScanJob(ctx context.Context, name, cronExpr string, config *ScanJobConfig) error

AddScanJob adds a new scheduled scan job.

func (*Scheduler) AddSmartScanJob added in v0.25.0

func (s *Scheduler) AddSmartScanJob(ctx context.Context, name, cronExpr string, config SmartScanJobConfig) error

AddSmartScanJob adds a new recurring smart-scan job to the schedule.

func (*Scheduler) DisableJob

func (s *Scheduler) DisableJob(ctx context.Context, jobID uuid.UUID) error

DisableJob disables a scheduled job.

func (*Scheduler) EnableJob

func (s *Scheduler) EnableJob(ctx context.Context, jobID uuid.UUID) error

EnableJob enables a scheduled job.

func (*Scheduler) GetJobs

func (s *Scheduler) GetJobs() []*ScheduledJob

GetJobs returns all scheduled jobs from the database.

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(ctx context.Context, jobID uuid.UUID) error

RemoveJob removes a scheduled job.

func (*Scheduler) Start

func (s *Scheduler) Start() error

Start begins the scheduler.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler.

func (*Scheduler) WithMaxConcurrentScans added in v0.13.0

func (s *Scheduler) WithMaxConcurrentScans(n int) *Scheduler

WithMaxConcurrentScans overrides the maximum number of host scans that may run in parallel within a single scan job execution. It returns the scheduler to allow call chaining. n <= 0 is treated as the default.

func (*Scheduler) WithScanQueue added in v0.13.0

func (s *Scheduler) WithScanQueue(q *scanning.ScanQueue) *Scheduler

WithScanQueue configures the scheduler to use the provided ScanQueue for executing host scans instead of the default semaphore+goroutine pattern. When set, processHostsForScanning submits scan requests to the queue and waits for all results before returning. Pass nil to revert to the default.

func (*Scheduler) WithSmartScanService added in v0.25.0

func (s *Scheduler) WithSmartScanService(svc smartScanBatcher) *Scheduler

WithSmartScanService attaches a SmartScanService so the scheduler can execute smart_scan type jobs. Must be called before Start.

type SmartScanJobConfig added in v0.25.0

type SmartScanJobConfig struct {
	// ScoreThreshold re-queues hosts with knowledge_score < threshold.
	// Defaults to 80 when zero.
	ScoreThreshold int `json:"score_threshold,omitempty"`
	// MaxStalenessHours re-queues hosts not seen within this many hours.
	// Ignored when zero.
	MaxStalenessHours int `json:"max_staleness_hours,omitempty"`
	// NetworkCIDR restricts the batch to hosts within the given network.
	// Empty means all networks.
	NetworkCIDR string `json:"network_cidr,omitempty"`
	// Limit caps the number of scans queued per cron fire. Defaults to the
	// SmartScanService batch limit when zero.
	Limit int `json:"limit,omitempty"`
}

SmartScanJobConfig configures a recurring scheduled smart scan. On each cron fire the scheduler calls QueueBatch with a staleness filter targeting hosts whose knowledge score is below the threshold or whose last_seen timestamp is older than MaxStalenessHours.

Jump to

Keyboard shortcuts

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