task

package
v0.6.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: PostgreSQL Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTaskNotFound = errors.New("task not found")

Functions

func Provide

func Provide(i *do.Injector)

Types

type LogEntry

type LogEntry struct {
	Timestamp time.Time
	Message   string
	Fields    map[string]any
}

type Options

type Options struct {
	ParentID            uuid.UUID `json:"parent_id"`
	DatabaseID          string    `json:"database_id"`
	NodeName            string    `json:"node_name"`
	InstanceID          string    `json:"instance_id"`
	HostID              string    `json:"host_id"`
	Type                Type      `json:"type"`
	WorkflowInstanceID  string    `json:"workflow_id"`
	WorkflowExecutionID string    `json:"workflow_execution_id"`
}

type Service

type Service struct {
	Store *Store
}

func NewService

func NewService(store *Store) *Service

func (*Service) AddLogEntry

func (s *Service) AddLogEntry(ctx context.Context, databaseID string, taskID uuid.UUID, entry LogEntry) error

func (*Service) CreateTask

func (s *Service) CreateTask(ctx context.Context, opts Options) (*Task, error)

func (*Service) DeleteAllTaskLogs

func (s *Service) DeleteAllTaskLogs(ctx context.Context, databaseID string) error

func (*Service) DeleteAllTasks

func (s *Service) DeleteAllTasks(ctx context.Context, databaseID string) error

func (*Service) DeleteTask

func (s *Service) DeleteTask(ctx context.Context, databaseID string, taskID uuid.UUID) error

func (*Service) DeleteTaskLogs

func (s *Service) DeleteTaskLogs(ctx context.Context, databaseID string, taskID uuid.UUID) error

func (*Service) GetTask

func (s *Service) GetTask(ctx context.Context, databaseID string, taskID uuid.UUID) (*Task, error)

func (*Service) GetTaskLog

func (s *Service) GetTaskLog(ctx context.Context, databaseID string, taskID uuid.UUID, options TaskLogOptions) (*TaskLog, error)

func (*Service) GetTasks

func (s *Service) GetTasks(ctx context.Context, databaseID string, options TaskListOptions) ([]*Task, error)

func (*Service) UpdateTask

func (s *Service) UpdateTask(ctx context.Context, task *Task) error

type SortOrder

type SortOrder string
const (
	SortAscend  SortOrder = "ascend"
	SortDescend SortOrder = "descend"
)

func (SortOrder) String

func (s SortOrder) String() string

type Status

type Status string
const (
	StatusPending   Status = "pending"
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusFailed    Status = "failed"
	StatusCanceled  Status = "canceled"
	StatusCanceling Status = "canceling"
	StatusUnknown   Status = "unknown"
)

func (Status) String

func (s Status) String() string

type Store

type Store struct {
	Task           *TaskStore
	TaskLogMessage *TaskLogEntryStore
	// contains filtered or unexported fields
}

func NewStore

func NewStore(client *clientv3.Client, root string) *Store

func (*Store) Txn

func (s *Store) Txn(ops ...storage.TxnOperation) storage.Txn

type StoredTask

type StoredTask struct {
	storage.StoredValue
	Task *Task `json:"task"`
}

type StoredTaskLogEntry

type StoredTaskLogEntry struct {
	storage.StoredValue
	DatabaseID string         `json:"database_id"`
	TaskID     uuid.UUID      `json:"task_id"`
	EntryID    uuid.UUID      `json:"entry_id"`
	Timestamp  time.Time      `json:"timestamp"`
	Message    string         `json:"message"`
	Fields     map[string]any `json:"fields"`
}

type Task

type Task struct {
	ParentID            uuid.UUID `json:"parent_id"`
	DatabaseID          string    `json:"database_id"`
	NodeName            string    `json:"node_name"`
	InstanceID          string    `json:"instance_id"`
	HostID              string    `json:"host_id"`
	TaskID              uuid.UUID `json:"task_id"`
	CreatedAt           time.Time `json:"created_at"`
	CompletedAt         time.Time `json:"completed_at"`
	Type                Type      `json:"type"`
	WorkflowInstanceID  string    `json:"workflow_id"`
	WorkflowExecutionID string    `json:"workflow_execution_id"`
	Status              Status    `json:"status"`
	Error               string    `json:"error"`
}

func NewTask

func NewTask(opts Options) (*Task, error)

func (*Task) IsComplete

func (t *Task) IsComplete() bool

func (*Task) SetCompleted

func (t *Task) SetCompleted()

func (*Task) SetFailed

func (t *Task) SetFailed(cause error)

func (*Task) Start

func (t *Task) Start()

func (*Task) Update

func (t *Task) Update(options UpdateOptions)

type TaskListOptions

type TaskListOptions struct {
	Limit       int
	AfterTaskID uuid.UUID
	SortOrder   SortOrder

	// Optional filters (applied client-side by helper methods)
	Type     Type
	NodeName string
	Statuses []Status
}

type TaskLog

type TaskLog struct {
	DatabaseID  string     `json:"database_id"`
	TaskID      uuid.UUID  `json:"id"`
	LastEntryID uuid.UUID  `json:"last_entry_id"`
	Entries     []LogEntry `json:"entries"`
}

type TaskLogEntryStore

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

func NewTaskLogEntryStore

func NewTaskLogEntryStore(client *clientv3.Client, root string) *TaskLogEntryStore

func (*TaskLogEntryStore) DatabasePrefix

func (s *TaskLogEntryStore) DatabasePrefix(databaseID string) string

func (*TaskLogEntryStore) DeleteByDatabaseID

func (s *TaskLogEntryStore) DeleteByDatabaseID(databaseID string) storage.DeleteOp

func (*TaskLogEntryStore) DeleteByTaskID

func (s *TaskLogEntryStore) DeleteByTaskID(databaseID string, taskID uuid.UUID) storage.DeleteOp

func (*TaskLogEntryStore) GetAllByTaskID

func (s *TaskLogEntryStore) GetAllByTaskID(databaseID string, taskID uuid.UUID, options TaskLogOptions) storage.GetMultipleOp[*StoredTaskLogEntry]

func (*TaskLogEntryStore) Key

func (s *TaskLogEntryStore) Key(databaseID string, taskID, entryID uuid.UUID) string

func (*TaskLogEntryStore) Prefix

func (s *TaskLogEntryStore) Prefix() string

func (*TaskLogEntryStore) Put

func (*TaskLogEntryStore) TaskPrefix

func (s *TaskLogEntryStore) TaskPrefix(databaseID string, taskID uuid.UUID) string

type TaskLogOptions

type TaskLogOptions struct {
	Limit        int
	AfterEntryID uuid.UUID
}

type TaskLogWriter

type TaskLogWriter struct {
	DatabaseID string
	TaskID     uuid.UUID
	// contains filtered or unexported fields
}

func NewTaskLogWriter

func NewTaskLogWriter(ctx context.Context, service *Service, databaseID string, taskID uuid.UUID) *TaskLogWriter

func (*TaskLogWriter) Close

func (w *TaskLogWriter) Close() error

func (*TaskLogWriter) Write

func (w *TaskLogWriter) Write(p []byte) (n int, err error)

type TaskStore

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

func NewTaskStore

func NewTaskStore(client *clientv3.Client, root string) *TaskStore

func (*TaskStore) Create

func (s *TaskStore) Create(item *StoredTask) storage.PutOp[*StoredTask]

func (*TaskStore) DatabasePrefix

func (s *TaskStore) DatabasePrefix(databaseID string) string

func (*TaskStore) Delete

func (s *TaskStore) Delete(databaseID string, taskID uuid.UUID) storage.DeleteOp

func (*TaskStore) DeleteByDatabaseID

func (s *TaskStore) DeleteByDatabaseID(databaseID string) storage.DeleteOp

func (*TaskStore) GetAllByDatabaseID

func (s *TaskStore) GetAllByDatabaseID(databaseID string, options TaskListOptions) storage.GetMultipleOp[*StoredTask]

func (*TaskStore) GetByKey

func (s *TaskStore) GetByKey(databaseID string, taskID uuid.UUID) storage.GetOp[*StoredTask]

func (*TaskStore) Key

func (s *TaskStore) Key(databaseID string, taskID uuid.UUID) string

func (*TaskStore) Prefix

func (s *TaskStore) Prefix() string

func (*TaskStore) Update

func (s *TaskStore) Update(item *StoredTask) storage.PutOp[*StoredTask]

type Type

type Type string
const (
	TypeCreate          Type = "create"
	TypeUpdate          Type = "update"
	TypeDelete          Type = "delete"
	TypeNodeBackup      Type = "node_backup"
	TypeRestore         Type = "restore"
	TypeNodeRestore     Type = "node_restore"
	TypeRestartInstance Type = "restart_instance"
	TypeStopInstance    Type = "stop_instance"
	TypeStartInstance   Type = "start_instance"
	TypeSwitchover      Type = "switchover"
	TypeFailover        Type = "failover"
	TypeRemoveHost      Type = "remove_host"
)

func (Type) String

func (t Type) String() string

type UpdateOptions

type UpdateOptions struct {
	NodeName            *string    `json:"node_name,omitempty"`
	InstanceID          *string    `json:"instance_id,omitempty"`
	HostID              *string    `json:"host_id,omitempty"`
	WorkflowInstanceID  *string    `json:"workflow_instance_id,omitempty"`
	WorkflowExecutionID *string    `json:"workflow_execution_id,omitempty"`
	CompletedAt         *time.Time `json:"completed_at,omitempty"`
	Status              *Status    `json:"status,omitempty"`
	Error               *string    `json:"error,omitempty"`
}

func UpdateCancel

func UpdateCancel() UpdateOptions

func UpdateComplete

func UpdateComplete() UpdateOptions

func UpdateFail

func UpdateFail(cause error) UpdateOptions

func UpdateStart

func UpdateStart() UpdateOptions

Jump to

Keyboard shortcuts

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