scheduler

package
v0.0.0-...-9b8dde8 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateNextRun

func CalculateNextRun(cron *CronExpression, after time.Time) (time.Time, error)

CalculateNextRun calculates the next run time for a cron expression after the given time.

func DescribeCronExpression

func DescribeCronExpression(cron *CronExpression) string

DescribeCronExpression returns a human-readable description of what the cron expression means.

Types

type Action

type Action struct {
	Type   ActionType        `json:"type"`
	Config map[string]string `json:"config,omitempty"`
}

Action represents an action to perform after a scan.

type ActionType

type ActionType string

ActionType specifies the type of post-scan action.

const (
	ActionReport      ActionType = "report"
	ActionNotify      ActionType = "notify"
	ActionCompare     ActionType = "compare"
	ActionWebhook     ActionType = "webhook"
	ActionSetBaseline ActionType = "set_baseline"
)

type CronExpression

type CronExpression struct {
	Minute     string // 0-59 or *
	Hour       string // 0-23 or *
	DayOfMonth string // 1-31 or *
	Month      string // 1-12 or *
	DayOfWeek  string // 0-7 or * (0 and 7 are Sunday)
}

CronExpression represents a parsed cron expression.

func ParseCronExpression

func ParseCronExpression(expr string) (*CronExpression, error)

ParseCronExpression parses a cron expression and returns a CronExpression. Supports standard 5-field cron syntax: minute hour day-of-month month day-of-week Examples:

  • "0 2 * * *" = Every day at 2:00 AM
  • "*/15 * * * *" = Every 15 minutes
  • "0 */2 * * *" = Every 2 hours
  • "0 0 1 * *" = First day of every month at midnight

func (*CronExpression) String

func (c *CronExpression) String() string

String returns a human-readable description of the cron expression.

type Manager

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

Manager manages scheduled scans and workflows.

func NewManager

func NewManager(storage *Storage) *Manager

NewManager creates a new scheduler manager.

func (*Manager) GetScheduleStatus

func (m *Manager) GetScheduleStatus(scheduleID string) (*ScheduleStatus, error)

GetScheduleStatus returns the current status of a schedule.

func (*Manager) ListActiveJobs

func (m *Manager) ListActiveJobs() []string

ListActiveJobs returns all currently running jobs.

func (*Manager) RunScheduleNow

func (m *Manager) RunScheduleNow(scheduleID string) error

RunScheduleNow manually triggers a schedule to run immediately.

func (*Manager) Start

func (m *Manager) Start() error

Start starts the scheduler manager.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the scheduler manager.

type Schedule

type Schedule struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"description,omitempty"`
	Enabled     bool       `json:"enabled"`
	CronExpr    string     `json:"cron_expr"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
	LastRun     *time.Time `json:"last_run,omitempty"`
	NextRun     *time.Time `json:"next_run,omitempty"`

	// Scan configuration
	Target   string            `json:"target"`
	Template string            `json:"template,omitempty"`
	ScanType string            `json:"scan_type"` // blitz, raider, full
	Options  map[string]string `json:"options,omitempty"`

	// Actions to perform after scan
	Actions []Action `json:"actions,omitempty"`
}

Schedule represents a scheduled scan configuration.

type ScheduleStatus

type ScheduleStatus struct {
	Schedule    Schedule
	IsRunning   bool
	LastRunTime *time.Time
	LastError   string
	RunCount    int
}

ScheduleStatus represents the current status of a schedule.

type StepExecution

type StepExecution struct {
	StepName    string                 `json:"step_name"`
	Status      StepStatus             `json:"status"`
	StartedAt   time.Time              `json:"started_at"`
	CompletedAt *time.Time             `json:"completed_at,omitempty"`
	Error       string                 `json:"error,omitempty"`
	Output      map[string]interface{} `json:"output,omitempty"`
}

StepExecution represents the execution of a single workflow step.

type StepStatus

type StepStatus string

StepStatus represents the status of a step execution.

const (
	StepStatusPending   StepStatus = "pending"
	StepStatusRunning   StepStatus = "running"
	StepStatusCompleted StepStatus = "completed"
	StepStatusFailed    StepStatus = "failed"
	StepStatusSkipped   StepStatus = "skipped"
)

type Storage

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

Storage manages persistent storage of schedules and workflows.

func NewStorage

func NewStorage(configDir string) (*Storage, error)

NewStorage creates a new Storage instance.

func (*Storage) DeleteSchedule

func (s *Storage) DeleteSchedule(id string) error

DeleteSchedule deletes a schedule by ID.

func (*Storage) DeleteWorkflow

func (s *Storage) DeleteWorkflow(id string) error

DeleteWorkflow deletes a workflow by ID.

func (*Storage) FindScheduleByName

func (s *Storage) FindScheduleByName(name string) (*Schedule, error)

FindScheduleByName finds a schedule by name (case-insensitive).

func (*Storage) FindWorkflowByName

func (s *Storage) FindWorkflowByName(name string) (*Workflow, error)

FindWorkflowByName finds a workflow by name (case-insensitive).

func (*Storage) ListSchedules

func (s *Storage) ListSchedules() ([]*Schedule, error)

ListSchedules returns all schedules.

func (*Storage) ListWorkflows

func (s *Storage) ListWorkflows() ([]*Workflow, error)

ListWorkflows returns all workflows.

func (*Storage) LoadSchedule

func (s *Storage) LoadSchedule(id string) (*Schedule, error)

LoadSchedule loads a schedule by ID.

func (*Storage) LoadWorkflow

func (s *Storage) LoadWorkflow(id string) (*Workflow, error)

LoadWorkflow loads a workflow by ID.

func (*Storage) SaveSchedule

func (s *Storage) SaveSchedule(schedule *Schedule) error

SaveSchedule persists a schedule to disk.

func (*Storage) SaveWorkflow

func (s *Storage) SaveWorkflow(workflow *Workflow) error

SaveWorkflow persists a workflow to disk.

type Workflow

type Workflow struct {
	ID          string            `yaml:"-" json:"id"`
	Name        string            `yaml:"name" json:"name"`
	Description string            `yaml:"description" json:"description"`
	Enabled     bool              `yaml:"-" json:"enabled"`
	Trigger     WorkflowTrigger   `yaml:"trigger" json:"trigger"`
	Steps       []WorkflowStep    `yaml:"steps" json:"steps"`
	Variables   map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`
	CreatedAt   time.Time         `yaml:"-" json:"created_at"`
	UpdatedAt   time.Time         `yaml:"-" json:"updated_at"`
}

Workflow represents an automated workflow definition.

func LoadWorkflowFromFile

func LoadWorkflowFromFile(path string) (*Workflow, error)

LoadWorkflowFromFile loads a workflow definition from a YAML file.

func ParseWorkflowYAML

func ParseWorkflowYAML(data []byte) (*Workflow, error)

ParseWorkflowYAML parses a workflow from YAML data.

type WorkflowEngine

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

WorkflowEngine executes workflows.

func NewWorkflowEngine

func NewWorkflowEngine(storage *Storage) *WorkflowEngine

NewWorkflowEngine creates a new workflow engine.

func (*WorkflowEngine) Execute

func (e *WorkflowEngine) Execute(ctx context.Context, workflow *Workflow) (*WorkflowExecution, error)

Execute executes a workflow.

type WorkflowExecution

type WorkflowExecution struct {
	ID          string                  `json:"id"`
	WorkflowID  string                  `json:"workflow_id"`
	Status      WorkflowExecutionStatus `json:"status"`
	StartedAt   time.Time               `json:"started_at"`
	CompletedAt *time.Time              `json:"completed_at,omitempty"`
	Steps       []StepExecution         `json:"steps"`
	Error       string                  `json:"error,omitempty"`
	Context     map[string]interface{}  `json:"context,omitempty"` // Shared context between steps
}

WorkflowExecution represents a workflow execution instance.

type WorkflowExecutionStatus

type WorkflowExecutionStatus string

WorkflowExecutionStatus represents the status of a workflow execution.

const (
	ExecutionStatusPending   WorkflowExecutionStatus = "pending"
	ExecutionStatusRunning   WorkflowExecutionStatus = "running"
	ExecutionStatusCompleted WorkflowExecutionStatus = "completed"
	ExecutionStatusFailed    WorkflowExecutionStatus = "failed"
	ExecutionStatusCancelled WorkflowExecutionStatus = "cancelled"
)

type WorkflowStep

type WorkflowStep struct {
	Name      string            `yaml:"name" json:"name"`
	Action    string            `yaml:"action" json:"action"` // scan, compare, notify, report
	Condition string            `yaml:"condition,omitempty" json:"condition,omitempty"`
	Config    map[string]string `yaml:"config,omitempty" json:"config,omitempty"`
}

WorkflowStep represents a single step in a workflow.

type WorkflowTrigger

type WorkflowTrigger struct {
	Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"` // Cron expression
	Webhook  bool   `yaml:"webhook,omitempty" json:"webhook,omitempty"`   // Enable webhook trigger
	Manual   bool   `yaml:"manual,omitempty" json:"manual,omitempty"`     // Allow manual trigger
}

WorkflowTrigger defines when a workflow should run.

Jump to

Keyboard shortcuts

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