scheduler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration extends time.ParseDuration with support for days ("d"). Examples: "1d" = 24h, "2d12h" = 60h, "30m", "2h30m".

Types

type AgentExecutor

type AgentExecutor interface {
	Execute(ctx context.Context, agentName string, prompt string) (*JobResult, error)
}

AgentExecutor defines the interface for executing agent tasks

type JSONStore

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

JSONStore implements TaskStore using JSON file storage

func NewJSONStore

func NewJSONStore(filePath string) (*JSONStore, error)

NewJSONStore creates a new JSON-based task store

func (*JSONStore) Close

func (s *JSONStore) Close() error

Close releases resources (no-op for JSON store)

func (*JSONStore) Create

func (s *JSONStore) Create(task *Task) error

Create adds a new task

func (*JSONStore) Delete

func (s *JSONStore) Delete(id string) error

Delete removes a task

func (*JSONStore) Get

func (s *JSONStore) Get(id string) (*Task, error)

Get retrieves a task by ID

func (*JSONStore) GetAll

func (s *JSONStore) GetAll() ([]*Task, error)

GetAll retrieves all tasks

func (*JSONStore) GetByAgent

func (s *JSONStore) GetByAgent(agentName string) ([]*Task, error)

GetByAgent retrieves all tasks for a specific agent

func (*JSONStore) GetDue

func (s *JSONStore) GetDue() ([]*Task, error)

GetDue retrieves tasks that are due for execution

func (*JSONStore) GetRuns

func (s *JSONStore) GetRuns(taskID string, limit int) ([]*TaskRun, error)

GetRuns retrieves execution history for a task

func (*JSONStore) LogRun

func (s *JSONStore) LogRun(run *TaskRun) error

LogRun records a task execution

func (*JSONStore) Update

func (s *JSONStore) Update(task *Task) error

Update updates an existing task

type JobResult

type JobResult struct {
	Response string
	Error    error
}

JobResult represents the result of an agent execution

type ScheduleType

type ScheduleType string
const (
	ScheduleTypeCron     ScheduleType = "cron"
	ScheduleTypeInterval ScheduleType = "interval"
	ScheduleTypeOnce     ScheduleType = "once"
)

type Scheduler

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

Scheduler manages scheduled tasks

func NewScheduler

func NewScheduler(store TaskStore, executor AgentExecutor, pollInterval time.Duration) *Scheduler

NewScheduler creates a new scheduler with the given store and executor

func (*Scheduler) CancelRunningTask

func (s *Scheduler) CancelRunningTask(id string) error

CancelRunningTask cancels a currently running task

func (*Scheduler) CreateTask

func (s *Scheduler) CreateTask(task *Task) error

CreateTask adds a new task

func (*Scheduler) DeleteTask

func (s *Scheduler) DeleteTask(id string) error

DeleteTask removes a task

func (*Scheduler) GetAllTasks

func (s *Scheduler) GetAllTasks() ([]*Task, error)

GetAllTasks retrieves all tasks

func (*Scheduler) GetTask

func (s *Scheduler) GetTask(id string) (*Task, error)

GetTask retrieves a task by ID

func (*Scheduler) GetTaskRuns

func (s *Scheduler) GetTaskRuns(taskID string, limit int) ([]*TaskRun, error)

GetTaskRuns retrieves execution history for a task

func (*Scheduler) GetTasksByAgent

func (s *Scheduler) GetTasksByAgent(agentName string) ([]*Task, error)

GetTasksByAgent retrieves all tasks for a specific agent

func (*Scheduler) PauseTask

func (s *Scheduler) PauseTask(id string) error

PauseTask pauses a task

func (*Scheduler) ResumeTask

func (s *Scheduler) ResumeTask(id string) error

ResumeTask resumes a paused task

func (*Scheduler) Start

func (s *Scheduler) Start()

Start begins the scheduler's polling loop

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop gracefully stops the scheduler

func (*Scheduler) UpdateTask

func (s *Scheduler) UpdateTask(task *Task) error

UpdateTask updates an existing task

type Task

type Task struct {
	ID            string                 `json:"id"`
	AgentName     string                 `json:"agent_name"`
	Prompt        string                 `json:"prompt"`
	ScheduleType  ScheduleType           `json:"schedule_type"`
	ScheduleValue string                 `json:"schedule_value"`
	Status        TaskStatus             `json:"status"`
	NextRun       time.Time              `json:"next_run"`
	LastRun       *time.Time             `json:"last_run,omitempty"`
	CreatedAt     time.Time              `json:"created_at"`
	UpdatedAt     time.Time              `json:"updated_at"`
	ContextMode   string                 `json:"context_mode"`
	Metadata      map[string]interface{} `json:"metadata,omitempty"`
}

Task represents a scheduled task

func NewTask

func NewTask(agentName, prompt string, scheduleType ScheduleType, scheduleValue string) (*Task, error)

NewTask creates a new task with the given parameters

func (*Task) CalculateNextRun

func (t *Task) CalculateNextRun() error

CalculateNextRun calculates the next run time based on schedule type

func (*Task) IsDue

func (t *Task) IsDue() bool

IsDue checks if the task should be executed now

type TaskRun

type TaskRun struct {
	ID         string    `json:"id"`
	TaskID     string    `json:"task_id"`
	RunAt      time.Time `json:"run_at"`
	DurationMs int64     `json:"duration_ms"`
	Status     string    `json:"status"` // "success", "error", "timeout"
	Result     string    `json:"result,omitempty"`
	Error      string    `json:"error,omitempty"`
}

TaskRun represents a single execution of a task

func NewTaskRun

func NewTaskRun(taskID string) *TaskRun

NewTaskRun creates a new task run record

type TaskStatus

type TaskStatus string
const (
	TaskStatusActive TaskStatus = "active"
	TaskStatusPaused TaskStatus = "paused"
)

type TaskStore

type TaskStore interface {
	// Create adds a new task
	Create(task *Task) error

	// Get retrieves a task by ID
	Get(id string) (*Task, error)

	// GetAll retrieves all tasks
	GetAll() ([]*Task, error)

	// GetDue retrieves tasks that are due for execution
	GetDue() ([]*Task, error)

	// GetByAgent retrieves all tasks for a specific agent
	GetByAgent(agentName string) ([]*Task, error)

	// Update updates an existing task
	Update(task *Task) error

	// Delete removes a task
	Delete(id string) error

	// LogRun records a task execution
	LogRun(run *TaskRun) error

	// GetRuns retrieves execution history for a task
	GetRuns(taskID string, limit int) ([]*TaskRun, error)

	// Close releases resources
	Close() error
}

TaskStore defines the interface for task persistence

Jump to

Keyboard shortcuts

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