task

package
v1.5.20 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	ID       uuid.UUID     `json:"id"`
	Task     *Task         `json:"task"`
	Args     util.ValueMap `json:"args,omitempty"`
	Started  time.Time     `json:"started,omitempty"`
	Elapsed  int           `json:"elapsed,omitempty"`
	Status   string        `json:"status,omitempty"`
	Summary  string        `json:"summary,omitempty"`
	Logs     []string      `json:"logs,omitempty"`
	Data     any           `json:"data,omitempty"`
	Metadata util.ValueMap `json:"metadata,omitempty"`
	Success  bool          `json:"success"`
	Error    string        `json:"error,omitempty"`
	// contains filtered or unexported fields
}

func CompletedResult

func CompletedResult(key string, task *Task, args util.ValueMap, data any, err error, logs ...string) *Result

func NewResult

func NewResult(task *Task, args util.ValueMap, fns ...ResultLogFn) *Result

func (*Result) AddLogs

func (r *Result) AddLogs(msgs ...string)

func (*Result) Complete

func (r *Result) Complete(data any, errs ...error) *Result

func (*Result) CompleteError

func (r *Result) CompleteError(err error) *Result

func (*Result) CompleteSimple

func (r *Result) CompleteSimple(data any) *Result

func (*Result) EndTime

func (r *Result) EndTime() time.Time

func (*Result) IsOK

func (r *Result) IsOK() bool

func (*Result) Log

func (r *Result) Log(msg string, args ...any)

func (*Result) String

func (r *Result) String() string

func (*Result) Summarize

func (r *Result) Summarize() string

type ResultLogFn

type ResultLogFn func(key string, data any)

type Results

type Results []*Result

func (Results) ForAct

func (r Results) ForAct(act string) *Result

func (Results) Get

func (r Results) Get(id uuid.UUID) *Result

func (Results) Keys

func (r Results) Keys() []string

func (Results) Statuses

func (r Results) Statuses() ([]string, map[string]Results)

func (Results) String

func (r Results) String() string

type Service

type Service struct {
	RegisteredTasks Tasks `json:"tasks"`
	// contains filtered or unexported fields
}

func NewService

func NewService(fs filesystem.FileLoader, path string, initialTasks ...*Task) *Service

func (*Service) RegisterTask

func (s *Service) RegisterTask(t *Task) error

func (*Service) RemoveTask

func (s *Service) RemoveTask(key string) bool

func (*Service) Run

func (s *Service) Run(ctx context.Context, task *Task, args util.ValueMap, logger util.Logger, fns ...exec.OutFn) *Result

func (*Service) RunAll

func (s *Service) RunAll(ctx context.Context, task *Task, argsSet []util.ValueMap, logger util.Logger, fns ...exec.OutFn) (Results, error)

type Task

type Task struct {
	Key           string                 `json:"key"`
	Title         string                 `json:"title,omitempty"`
	Category      string                 `json:"category,omitempty"`
	Icon          string                 `json:"icon,omitempty"`
	Description   string                 `json:"description,omitempty"`
	Tags          []string               `json:"tags,omitempty"`
	Fields        func() util.FieldDescs `json:"args,omitempty"`
	Dangerous     string                 `json:"dangerous,omitempty"`
	WebURL        string                 `json:"webURL,omitempty"`
	MaxConcurrent int                    `json:"maxConcurrent,omitempty"`
	// contains filtered or unexported fields
}

func NewTask

func NewTask(key string, title string, cat string, icon string, desc string, fns ...TaskFn) *Task

func (*Task) Clone

func (t *Task) Clone() *Task

func (*Task) IconSafe

func (t *Task) IconSafe() string

func (*Task) Run

func (t *Task) Run(ctx context.Context, args util.ValueMap, logger util.Logger, fns ...exec.OutFn) *Result

func (*Task) RunWithResult

func (t *Task) RunWithResult(ctx context.Context, res *Result, logger util.Logger) *Result

func (*Task) TitleSafe

func (t *Task) TitleSafe() string

func (*Task) WebPath

func (t *Task) WebPath() string

func (*Task) WithTags

func (t *Task) WithTags(tags []string) *Task

type TaskFn

type TaskFn func(ctx context.Context, res *Result, logger util.Logger) error

type Tasks

type Tasks []*Task

func (Tasks) ByCategory

func (a Tasks) ByCategory(key string) Tasks

func (Tasks) Categories

func (a Tasks) Categories() []string

func (Tasks) Clone

func (a Tasks) Clone() Tasks

func (Tasks) Get

func (a Tasks) Get(key string) *Task

func (Tasks) Keys

func (a Tasks) Keys() []string

func (Tasks) Sort

func (a Tasks) Sort()

Jump to

Keyboard shortcuts

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