Documentation
¶
Index ¶
- type Scheduler
- type TaskExecutor
- type TaskScheduler
- func (s *TaskScheduler) AddTask(ctx context.Context, task *db.ScheduledTask) (int64, error)
- func (s *TaskScheduler) EditTask(ctx context.Context, taskID int64, schedule, taskType, prompt *string, ...) error
- func (s *TaskScheduler) GetTask(ctx context.Context, taskID int64) (*db.ScheduledTask, error)
- func (s *TaskScheduler) ListTasks(ctx context.Context, channelID string) ([]*db.ScheduledTask, error)
- func (s *TaskScheduler) RemoveTask(ctx context.Context, taskID int64) error
- func (s *TaskScheduler) SetTaskEnabled(ctx context.Context, taskID int64, enabled bool) error
- func (s *TaskScheduler) Start(ctx context.Context) error
- func (s *TaskScheduler) Stop() error
- func (s *TaskScheduler) ToggleTask(ctx context.Context, taskID int64) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler interface {
Start(ctx context.Context) error
Stop() error
AddTask(ctx context.Context, task *db.ScheduledTask) (int64, error)
RemoveTask(ctx context.Context, taskID int64) error
ListTasks(ctx context.Context, channelID string) ([]*db.ScheduledTask, error)
GetTask(ctx context.Context, taskID int64) (*db.ScheduledTask, error)
SetTaskEnabled(ctx context.Context, taskID int64, enabled bool) error
ToggleTask(ctx context.Context, taskID int64) (bool, error)
EditTask(ctx context.Context, taskID int64, schedule, taskType, prompt *string, autoDeleteSec *int) error
}
Scheduler manages scheduled tasks.
type TaskExecutor ¶
type TaskExecutor interface {
ExecuteTask(ctx context.Context, task *db.ScheduledTask) (string, error)
}
TaskExecutor executes a scheduled task and returns a response or error.
type TaskScheduler ¶
type TaskScheduler struct {
// contains filtered or unexported fields
}
TaskScheduler implements Scheduler using a polling loop.
func NewTaskScheduler ¶
func NewTaskScheduler(store db.Store, executor TaskExecutor, pollInterval time.Duration, logger *slog.Logger) *TaskScheduler
NewTaskScheduler creates a new TaskScheduler.
func (*TaskScheduler) AddTask ¶
func (s *TaskScheduler) AddTask(ctx context.Context, task *db.ScheduledTask) (int64, error)
AddTask calculates next_run_at, enables the task, and stores it.
func (*TaskScheduler) EditTask ¶
func (s *TaskScheduler) EditTask(ctx context.Context, taskID int64, schedule, taskType, prompt *string, autoDeleteSec *int) error
EditTask updates a scheduled task's schedule, type, prompt, and/or auto_delete_sec.
func (*TaskScheduler) GetTask ¶ added in v0.1.59
func (s *TaskScheduler) GetTask(ctx context.Context, taskID int64) (*db.ScheduledTask, error)
GetTask returns a single scheduled task by ID.
func (*TaskScheduler) ListTasks ¶
func (s *TaskScheduler) ListTasks(ctx context.Context, channelID string) ([]*db.ScheduledTask, error)
ListTasks returns all tasks for a channel.
func (*TaskScheduler) RemoveTask ¶
func (s *TaskScheduler) RemoveTask(ctx context.Context, taskID int64) error
RemoveTask deletes a task from the store.
func (*TaskScheduler) SetTaskEnabled ¶
SetTaskEnabled enables or disables a scheduled task.
func (*TaskScheduler) Start ¶
func (s *TaskScheduler) Start(ctx context.Context) error
Start launches the polling loop in a background goroutine.
func (*TaskScheduler) Stop ¶
func (s *TaskScheduler) Stop() error
Stop gracefully stops the polling loop and waits for it to finish.
func (*TaskScheduler) ToggleTask ¶
ToggleTask flips a scheduled task's enabled state and returns the new state.