task

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONMap

type JSONMap map[string]interface{}

JSONMap is a custom type for handling JSON maps in GORM

func (*JSONMap) Scan

func (j *JSONMap) Scan(value interface{}) error

Scan implements the Scanner interface for database deserialization

func (JSONMap) Value

func (j JSONMap) Value() (driver.Value, error)

Value implements the Valuer interface for database serialization

type Service

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

Service provides task orchestration functionality

func NewService

func NewService() *Service

NewService creates a new task service

func (*Service) CreateTask

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

CreateTask creates a new task

func (*Service) DeleteTask

func (s *Service) DeleteTask(ctx context.Context, userID string, taskID uint) error

DeleteTask deletes a task

func (*Service) GetTask

func (s *Service) GetTask(ctx context.Context, userID string, taskID uint) (*Task, error)

GetTask retrieves a task by ID

func (*Service) ListTasks

func (s *Service) ListTasks(ctx context.Context, userID string) ([]*Task, error)

ListTasks returns all tasks for a user

func (*Service) SetDB

func (s *Service) SetDB(db *gorm.DB)

SetDB sets the database connection

func (*Service) UpdateTaskStatus

func (s *Service) UpdateTaskStatus(ctx context.Context, userID string, taskID uint, status TaskStatus) error

UpdateTaskStatus updates the status of a task

type Task

type Task struct {
	ID          uint           `json:"id" gorm:"primaryKey"`
	Name        string         `json:"name" gorm:"not null"`
	Description string         `json:"description"`
	Type        string         `json:"type" gorm:"not null"`
	UserID      string         `json:"user_id" gorm:"index;not null"`
	Status      TaskStatus     `json:"status" gorm:"default:0"`
	Priority    int            `json:"priority" gorm:"default:0"`
	Config      JSONMap        `json:"config" gorm:"type:text"`
	Result      JSONMap        `json:"result" gorm:"type:text"`
	Error       string         `json:"error"`
	ScheduledAt *time.Time     `json:"scheduled_at"`
	StartedAt   *time.Time     `json:"started_at"`
	CompletedAt *time.Time     `json:"completed_at"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `json:"-" gorm:"index"`
}

Task represents a task in the system

func (Task) TableName

func (Task) TableName() string

TableName returns the table name for the Task model

type TaskStatus

type TaskStatus int

TaskStatus represents the status of a task

const (
	TaskStatusPending TaskStatus = iota
	TaskStatusRunning
	TaskStatusCompleted
	TaskStatusFailed
	TaskStatusCancelled
)

func (TaskStatus) String

func (t TaskStatus) String() string

String returns the string representation of TaskStatus

Jump to

Keyboard shortcuts

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