Documentation
¶
Overview ¶
Package scheduler provides scheduled message delivery for AI agent sessions.
Index ¶
- Constants
- type PersistedTaskState
- type ScheduledTask
- func (t *ScheduledTask) Attempts() int
- func (t *ScheduledTask) CompareAndSwapStatus(old, new taskStatus) bool
- func (t *ScheduledTask) IncrementAttempts() int
- func (t *ScheduledTask) LastError() string
- func (t *ScheduledTask) MarshalJSON() ([]byte, error)
- func (t *ScheduledTask) SetLastError(err string)
- func (t *ScheduledTask) SetStatus(s TaskStatus)
- func (t *ScheduledTask) Status() TaskStatus
- func (t *ScheduledTask) ToJSON() map[string]interface{}
- func (t *ScheduledTask) UnmarshalJSON(data []byte) error
- type Scheduler
- func (s *Scheduler) Cancel(taskID string) error
- func (s *Scheduler) GetTask(taskID string) (*ScheduledTask, bool)
- func (s *Scheduler) Info() SchedulerInfo
- func (s *Scheduler) ListPendingTasks(projectPath string, global bool) []*ScheduledTask
- func (s *Scheduler) ListTasks(projectPath string, global bool) []*ScheduledTask
- func (s *Scheduler) Schedule(sessionCode string, duration time.Duration, message string, projectPath string) (*ScheduledTask, error)
- func (s *Scheduler) Start(ctx context.Context) error
- func (s *Scheduler) Stop(ctx context.Context)
- type SchedulerConfig
- type SchedulerInfo
- type SchedulerStateManager
- func (m *SchedulerStateManager) ClearProject(projectPath string) error
- func (m *SchedulerStateManager) ListProjectsWithTasks() []string
- func (m *SchedulerStateManager) LoadAllTasks() []*ScheduledTask
- func (m *SchedulerStateManager) LoadTasks(projectPath string) ([]*ScheduledTask, error)
- func (m *SchedulerStateManager) RegisterProject(projectPath string)
- func (m *SchedulerStateManager) RemoveTask(taskID string, projectPath string) error
- func (m *SchedulerStateManager) SaveTask(task *ScheduledTask) error
- func (m *SchedulerStateManager) ScanForProjects(basePaths []string)
- type TaskStatus
Constants ¶
const SchedulerStateDir = ".agnt"
SchedulerStateDir is the directory within each project for agnt state.
const SchedulerStateFile = "scheduled-tasks.json"
SchedulerStateFile is the name of the per-project task state file.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PersistedTaskState ¶
type PersistedTaskState struct {
Version int `json:"version"`
Tasks []*ScheduledTask `json:"tasks"`
UpdatedAt string `json:"updated_at"`
}
PersistedTaskState represents the structure of the task state file.
type ScheduledTask ¶
type ScheduledTask struct {
ID string `json:"id"` // Unique task ID (e.g., "task-abc123")
SessionCode string `json:"session_code"` // Target session
Message string `json:"message"` // Message to deliver
DeliverAt time.Time `json:"deliver_at"` // Scheduled delivery time
CreatedAt time.Time `json:"created_at"` // When task was created
ProjectPath string `json:"project_path"` // For project-scoped filtering
// contains filtered or unexported fields
}
ScheduledTask represents a message scheduled for future delivery. All mutable fields use atomic operations for lock-free concurrent access.
func NewScheduledTask ¶
func NewScheduledTask(id, sessionCode, message, projectPath string, deliverAt, createdAt time.Time, status TaskStatus) *ScheduledTask
NewScheduledTask creates a ScheduledTask with the given initial status.
func (*ScheduledTask) Attempts ¶
func (t *ScheduledTask) Attempts() int
Attempts returns the current attempt count.
func (*ScheduledTask) CompareAndSwapStatus ¶
func (t *ScheduledTask) CompareAndSwapStatus(old, new taskStatus) bool
CompareAndSwapStatus atomically transitions from old to new status. Returns true if the swap succeeded.
func (*ScheduledTask) IncrementAttempts ¶
func (t *ScheduledTask) IncrementAttempts() int
IncrementAttempts atomically increments and returns the new attempt count.
func (*ScheduledTask) LastError ¶
func (t *ScheduledTask) LastError() string
LastError returns the last error message.
func (*ScheduledTask) MarshalJSON ¶
func (t *ScheduledTask) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler for atomic-safe serialization.
func (*ScheduledTask) SetLastError ¶
func (t *ScheduledTask) SetLastError(err string)
SetLastError sets the last error message.
func (*ScheduledTask) SetStatus ¶
func (t *ScheduledTask) SetStatus(s TaskStatus)
SetStatus sets the task status.
func (*ScheduledTask) Status ¶
func (t *ScheduledTask) Status() TaskStatus
Status returns the current task status as a string.
func (*ScheduledTask) ToJSON ¶
func (t *ScheduledTask) ToJSON() map[string]interface{}
ToJSON returns the task as a JSON-serializable map.
func (*ScheduledTask) UnmarshalJSON ¶
func (t *ScheduledTask) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler for atomic-safe deserialization.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages scheduled message delivery.
func NewScheduler ¶
func NewScheduler(config SchedulerConfig, registry *session.SessionRegistry, stateMgr *SchedulerStateManager) *Scheduler
NewScheduler creates a new scheduler.
func (*Scheduler) Cancel ¶
Cancel cancels a scheduled task. Uses atomic CAS to prevent races with concurrent delivery.
func (*Scheduler) GetTask ¶
func (s *Scheduler) GetTask(taskID string) (*ScheduledTask, bool)
GetTask retrieves a task by ID.
func (*Scheduler) Info ¶
func (s *Scheduler) Info() SchedulerInfo
Info returns statistics about the scheduler.
func (*Scheduler) ListPendingTasks ¶
func (s *Scheduler) ListPendingTasks(projectPath string, global bool) []*ScheduledTask
ListPendingTasks returns only pending tasks.
func (*Scheduler) ListTasks ¶
func (s *Scheduler) ListTasks(projectPath string, global bool) []*ScheduledTask
ListTasks returns all tasks, optionally filtered by project path.
func (*Scheduler) Schedule ¶
func (s *Scheduler) Schedule(sessionCode string, duration time.Duration, message string, projectPath string) (*ScheduledTask, error)
Schedule adds a new task to the scheduler.
type SchedulerConfig ¶
type SchedulerConfig struct {
// TickInterval is how often the scheduler checks for due tasks.
TickInterval time.Duration
// MaxRetries is the maximum number of delivery attempts.
MaxRetries int
// RetryDelay is the base delay between retries (exponential backoff).
RetryDelay time.Duration
// DeliveryTimeout is the timeout for each delivery attempt.
DeliveryTimeout time.Duration
// MaxConcurrentDeliveries limits simultaneous delivery goroutines.
// Default: 10
MaxConcurrentDeliveries int64
}
SchedulerConfig configures the scheduler.
func DefaultSchedulerConfig ¶
func DefaultSchedulerConfig() SchedulerConfig
DefaultSchedulerConfig returns sensible defaults.
type SchedulerInfo ¶
type SchedulerInfo struct {
TotalScheduled int64 `json:"total_scheduled"`
TotalDelivered int64 `json:"total_delivered"`
TotalFailed int64 `json:"total_failed"`
TotalCancelled int64 `json:"total_cancelled"`
PendingCount int64 `json:"pending_count"`
}
SchedulerInfo contains statistics about the scheduler.
type SchedulerStateManager ¶
type SchedulerStateManager struct {
// contains filtered or unexported fields
}
SchedulerStateManager handles persisting scheduled tasks per-project.
func NewSchedulerStateManager ¶
func NewSchedulerStateManager() *SchedulerStateManager
NewSchedulerStateManager creates a new scheduler state manager.
func (*SchedulerStateManager) ClearProject ¶
func (m *SchedulerStateManager) ClearProject(projectPath string) error
ClearProject removes all tasks for a project.
func (*SchedulerStateManager) ListProjectsWithTasks ¶
func (m *SchedulerStateManager) ListProjectsWithTasks() []string
ListProjectsWithTasks returns all known project directories with tasks.
func (*SchedulerStateManager) LoadAllTasks ¶
func (m *SchedulerStateManager) LoadAllTasks() []*ScheduledTask
LoadAllTasks loads all tasks from all known project directories.
func (*SchedulerStateManager) LoadTasks ¶
func (m *SchedulerStateManager) LoadTasks(projectPath string) ([]*ScheduledTask, error)
LoadTasks loads all tasks for a specific project.
func (*SchedulerStateManager) RegisterProject ¶
func (m *SchedulerStateManager) RegisterProject(projectPath string)
RegisterProject registers a project directory for task tracking.
func (*SchedulerStateManager) RemoveTask ¶
func (m *SchedulerStateManager) RemoveTask(taskID string, projectPath string) error
RemoveTask removes a task from the project's state file.
func (*SchedulerStateManager) SaveTask ¶
func (m *SchedulerStateManager) SaveTask(task *ScheduledTask) error
SaveTask saves or updates a task in the project's state file.
func (*SchedulerStateManager) ScanForProjects ¶
func (m *SchedulerStateManager) ScanForProjects(basePaths []string)
ScanForProjects scans directories for existing task state files. This is called at daemon startup to discover persisted tasks.
type TaskStatus ¶
type TaskStatus string
TaskStatus represents the string form of a task status for JSON serialization.
const ( // TaskStatusPending indicates the task is waiting to be delivered. TaskStatusPending TaskStatus = "pending" // TaskStatusDelivering indicates the task is currently being delivered. TaskStatusDelivering TaskStatus = "delivering" // TaskStatusDelivered indicates the task was successfully delivered. TaskStatusDelivered TaskStatus = "delivered" // TaskStatusFailed indicates the task failed after max retries. TaskStatusFailed TaskStatus = "failed" // TaskStatusCancelled indicates the task was cancelled. TaskStatusCancelled TaskStatus = "cancelled" )