scheduledjob

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnavailable           = errors.New("scheduled job service unavailable")
	ErrProjectNotFound       = domain.ErrProjectNotFound
	ErrWorkflowNotFound      = domain.ErrWorkflowNotFound
	ErrScheduledJobNotFound  = domain.ErrScheduledJobNotFound
	ErrScheduledJobConflict  = domain.ErrScheduledJobConflict
	ErrStatusNotFound        = domain.ErrStatusNotFound
	ErrInvalidCronExpression = errors.New("scheduled job cron expression is invalid")
	ErrInvalidTicketTemplate = errors.New("scheduled job ticket template is invalid")
)

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	ProjectID      uuid.UUID
	Name           string
	CronExpression string
	TicketTemplate TicketTemplate
	IsEnabled      bool
}

type DeleteResult

type DeleteResult struct {
	DeletedJobID uuid.UUID `json:"deleted_job_id"`
}

type Optional

type Optional[T any] struct {
	Set   bool
	Value T
}

func Some

func Some[T any](value T) Optional[T]

type Repository

type Repository interface {
	EnsureProjectExists(ctx context.Context, projectID uuid.UUID) error
	ListProjectRepoIDs(ctx context.Context, projectID uuid.UUID) ([]uuid.UUID, error)
	List(ctx context.Context, projectID uuid.UUID) ([]domain.Job, error)
	Get(ctx context.Context, jobID uuid.UUID) (domain.Job, error)
	Create(ctx context.Context, job domain.Job) (domain.Job, error)
	Update(ctx context.Context, job domain.Job) (domain.Job, error)
	Delete(ctx context.Context, jobID uuid.UUID) error
	ListDue(ctx context.Context, now time.Time) ([]domain.Job, error)
	LoadWorkflow(ctx context.Context, projectID uuid.UUID, workflowID uuid.UUID) (domain.Workflow, error)
	ResolveStatusIDByName(ctx context.Context, projectID uuid.UUID, statusName string) (uuid.UUID, error)
}

type RunDueReport

type RunDueReport struct {
	JobsScanned    int `json:"jobs_scanned"`
	TicketsCreated int `json:"tickets_created"`
}

type ScheduledJob

type ScheduledJob struct {
	ID             uuid.UUID      `json:"id"`
	ProjectID      uuid.UUID      `json:"project_id"`
	Name           string         `json:"name"`
	CronExpression string         `json:"cron_expression"`
	TicketTemplate TicketTemplate `json:"ticket_template"`
	IsEnabled      bool           `json:"is_enabled"`
	LastRunAt      *time.Time     `json:"last_run_at,omitempty"`
	NextRunAt      *time.Time     `json:"next_run_at,omitempty"`
}

type Service

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

func NewService

func NewService(repo Repository, tickets ticketCreator, logger *slog.Logger) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, input CreateInput) (ScheduledJob, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, jobID uuid.UUID) (DeleteResult, error)

func (*Service) Get

func (s *Service) Get(ctx context.Context, jobID uuid.UUID) (ScheduledJob, error)

func (*Service) List

func (s *Service) List(ctx context.Context, projectID uuid.UUID) ([]ScheduledJob, error)

func (*Service) RunDue

func (s *Service) RunDue(ctx context.Context) (RunDueReport, error)

func (*Service) SetNowFunc

func (s *Service) SetNowFunc(now func() time.Time)

func (*Service) Trigger

func (s *Service) Trigger(ctx context.Context, jobID uuid.UUID) (TriggerResult, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, input UpdateInput) (ScheduledJob, error)

type TicketTemplate

type TicketTemplate struct {
	Title       string                    `json:"title"`
	Description string                    `json:"description"`
	Status      string                    `json:"status,omitempty"`
	Priority    ticketservice.Priority    `json:"priority"`
	Type        ticketservice.Type        `json:"type"`
	CreatedBy   string                    `json:"created_by"`
	BudgetUSD   float64                   `json:"budget_usd,omitempty"`
	RepoScopes  []TicketTemplateRepoScope `json:"repo_scopes,omitempty"`
}

func ParseRawTicketTemplate

func ParseRawTicketTemplate(raw map[string]any) (TicketTemplate, error)

func (TicketTemplate) Raw

func (t TicketTemplate) Raw() map[string]any

type TicketTemplateRepoScope added in v0.5.0

type TicketTemplateRepoScope struct {
	RepoID     uuid.UUID `json:"repo_id"`
	BranchName *string   `json:"branch_name,omitempty"`
}

type TriggerResult

type TriggerResult struct {
	Job    ScheduledJob         `json:"job"`
	Ticket ticketservice.Ticket `json:"ticket"`
}

type UpdateInput

type UpdateInput struct {
	JobID          uuid.UUID
	Name           Optional[string]
	CronExpression Optional[string]
	TicketTemplate Optional[TicketTemplate]
	IsEnabled      Optional[bool]
}

Jump to

Keyboard shortcuts

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