Documentation
¶
Overview ¶
Package service provides the main scheduler service for job management.
Index ¶
- type JobRequest
- type JobStatusResponse
- type QueueStats
- type SchedulerService
- func (s *SchedulerService) CancelJob(ctx context.Context, jobID string) error
- func (s *SchedulerService) CreateRecurringJob(ctx context.Context, req JobRequest, cronSpec string) (string, error)
- func (s *SchedulerService) GetJobStatus(ctx context.Context, jobID string) (*JobStatusResponse, error)
- func (s *SchedulerService) GetQueueStats(ctx context.Context) (map[string]QueueStats, error)
- func (s *SchedulerService) ListJobs(ctx context.Context, filter repository.JobFilter) ([]repository.Job, int64, error)
- func (s *SchedulerService) MarkJobCompleted(ctx context.Context, jobID string, result any) error
- func (s *SchedulerService) MarkJobFailed(ctx context.Context, jobID string, jobErr error) error
- func (s *SchedulerService) MarkJobRetrying(ctx context.Context, jobID string) error
- func (s *SchedulerService) MarkJobStarted(ctx context.Context, jobID string) error
- func (s *SchedulerService) ScheduleJob(ctx context.Context, req JobRequest, scheduleTime time.Time) (string, error)
- func (s *SchedulerService) Start() error
- func (s *SchedulerService) Stop() error
- func (s *SchedulerService) SubmitJob(ctx context.Context, req JobRequest) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JobRequest ¶
type JobRequest struct {
TaskType string `json:"task_type"`
Payload any `json:"payload"`
Queue string `json:"queue,omitempty"`
MaxRetries int `json:"max_retries,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
JobRequest represents a request to create a new job.
type JobStatusResponse ¶
type JobStatusResponse struct {
ID string `json:"id"`
TaskType string `json:"task_type"`
Status repository.JobStatus `json:"status"`
Queue string `json:"queue"`
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
StartedAt *time.Time `json:"started_at,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
FailedAt *time.Time `json:"failed_at,omitempty"`
RetryCount int `json:"retry_count"`
MaxRetries int `json:"max_retries"`
Error string `json:"error,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
CronExpression string `json:"cron_expression,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
JobStatusResponse represents the status response for a job.
type QueueStats ¶
type QueueStats struct {
Queue string `json:"queue"`
Size int `json:"size"`
Pending int `json:"pending"`
Active int `json:"active"`
Scheduled int `json:"scheduled"`
Retry int `json:"retry"`
Archived int `json:"archived"`
Completed int `json:"completed"`
Processed int `json:"processed"`
Failed int `json:"failed"`
}
QueueStats represents statistics for a queue.
type SchedulerService ¶
type SchedulerService struct {
// contains filtered or unexported fields
}
SchedulerService manages job scheduling and execution.
func NewSchedulerService ¶
func NewSchedulerService( qm *queue.Manager, repo repository.JobRepository, eb event.Dispatcher, ) *SchedulerService
NewSchedulerService creates a new scheduler service.
func (*SchedulerService) CancelJob ¶
func (s *SchedulerService) CancelJob(ctx context.Context, jobID string) error
CancelJob cancels a pending or scheduled job.
func (*SchedulerService) CreateRecurringJob ¶
func (s *SchedulerService) CreateRecurringJob(ctx context.Context, req JobRequest, cronSpec string) (string, error)
CreateRecurringJob sets up a cron-based recurring job.
func (*SchedulerService) GetJobStatus ¶
func (s *SchedulerService) GetJobStatus(ctx context.Context, jobID string) (*JobStatusResponse, error)
GetJobStatus retrieves current job status.
func (*SchedulerService) GetQueueStats ¶
func (s *SchedulerService) GetQueueStats(ctx context.Context) (map[string]QueueStats, error)
GetQueueStats retrieves statistics for the queues.
func (*SchedulerService) ListJobs ¶
func (s *SchedulerService) ListJobs(ctx context.Context, filter repository.JobFilter) ([]repository.Job, int64, error)
ListJobs lists jobs based on filter criteria.
func (*SchedulerService) MarkJobCompleted ¶
MarkJobCompleted marks a job as completed with result.
func (*SchedulerService) MarkJobFailed ¶
MarkJobFailed marks a job as failed with error.
func (*SchedulerService) MarkJobRetrying ¶
func (s *SchedulerService) MarkJobRetrying(ctx context.Context, jobID string) error
MarkJobRetrying marks a job as retrying.
func (*SchedulerService) MarkJobStarted ¶
func (s *SchedulerService) MarkJobStarted(ctx context.Context, jobID string) error
MarkJobStarted marks a job as started.
func (*SchedulerService) ScheduleJob ¶
func (s *SchedulerService) ScheduleJob(ctx context.Context, req JobRequest, scheduleTime time.Time) (string, error)
ScheduleJob schedules a job for future execution.
func (*SchedulerService) Start ¶
func (s *SchedulerService) Start() error
Start starts the scheduler service.
func (*SchedulerService) Stop ¶
func (s *SchedulerService) Stop() error
Stop stops the scheduler service.
func (*SchedulerService) SubmitJob ¶
func (s *SchedulerService) SubmitJob(ctx context.Context, req JobRequest) (string, error)
SubmitJob creates and enqueues a new job for immediate processing.