task

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultManager = NewManager()

DefaultManager is the global default task manager

Functions

This section is empty.

Types

type Manager

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

Manager manages background tasks

func NewManager

func NewManager() *Manager

NewManager creates a new task manager

func (*Manager) Cleanup

func (m *Manager) Cleanup(maxAge time.Duration)

Cleanup removes all completed tasks older than maxAge

func (*Manager) Create

func (m *Manager) Create(cmd *exec.Cmd, command, description string, ctx context.Context, cancel context.CancelFunc) *Task

Create creates and registers a new task

func (*Manager) Get

func (m *Manager) Get(id string) (*Task, bool)

Get retrieves a task by ID

func (*Manager) Kill

func (m *Manager) Kill(id string) error

Kill terminates a task by ID

func (*Manager) List

func (m *Manager) List() []*Task

List returns all tasks

func (*Manager) ListRunning

func (m *Manager) ListRunning() []*Task

ListRunning returns all running tasks

func (*Manager) Remove

func (m *Manager) Remove(id string)

Remove removes a completed task from the manager

type Task

type Task struct {
	ID          string             // Unique task ID
	Command     string             // The command being executed
	Description string             // Brief description
	Status      TaskStatus         // Current status
	PID         int                // Process ID
	StartTime   time.Time          // When the task started
	EndTime     time.Time          // When the task ended (if completed)
	ExitCode    int                // Exit code (if completed)
	Error       string             // Error message (if failed)
	Cmd         *exec.Cmd          // The running command
	Ctx         context.Context    // Task context
	Cancel      context.CancelFunc // Cancel function
	// contains filtered or unexported fields
}

Task represents a background task

func NewTask

func NewTask(id, command, description string, cmd *exec.Cmd, ctx context.Context, cancel context.CancelFunc) *Task

NewTask creates a new task

func (*Task) AppendOutput

func (t *Task) AppendOutput(data []byte)

AppendOutput appends data to the output buffer

func (*Task) Complete

func (t *Task) Complete(exitCode int, err error)

Complete marks the task as completed

func (*Task) GetOutput

func (t *Task) GetOutput() string

GetOutput returns the current output

func (*Task) GetStatus

func (t *Task) GetStatus() TaskInfo

GetStatus returns the current task status info

func (*Task) IsRunning

func (t *Task) IsRunning() bool

IsRunning returns true if the task is still running

func (*Task) Kill

func (t *Task) Kill()

Kill marks the task as killed

func (*Task) WaitForCompletion

func (t *Task) WaitForCompletion(timeout time.Duration) bool

WaitForCompletion waits until the task completes or timeout Returns true if completed, false if timeout

type TaskInfo

type TaskInfo struct {
	ID          string
	Command     string
	Description string
	Status      TaskStatus
	PID         int
	StartTime   time.Time
	EndTime     time.Time
	ExitCode    int
	Error       string
	Output      string
}

TaskInfo is a snapshot of task information

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a background task

const (
	StatusRunning   TaskStatus = "running"
	StatusCompleted TaskStatus = "completed"
	StatusFailed    TaskStatus = "failed"
	StatusKilled    TaskStatus = "killed"
)

Jump to

Keyboard shortcuts

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