Skip to content

Repository files navigation

Task Engine

CI/CD Pipelinecodecov

A Go task execution framework with built-in actions for file operations, Docker management, and system administration.

Quick Start

package main
import (
"context""log/slog""os""github.com/ndizazzo/task-engine""github.com/ndizazzo/task-engine/tasks"
)
funcmain() {
logger:=slog.New(slog.NewTextHandler(os.Stdout, nil))
// Create and run a tasktask:=tasks.NewFileOperationsTask(logger, "/tmp/myproject")
iferr:=task.Run(context.Background()); err!=nil {
logger.Error("Task failed", "error", err)
os.Exit(1)
}
}

Core Concepts

  • Tasks: Collections of actions that execute sequentially
  • Actions: Individual operations (file, Docker, system)
  • Parameters: Pass data between actions using ActionOutput() and TaskOutput(), and fetch rich results using ActionResult() and TaskResult()
  • Context: Share data across tasks with TaskManager

Built-in Actions

24+ actions for common operations:

  • File: Create, read, write, copy, compress, extract
  • Docker: Run, compose, health checks, image management
  • System: Service management, package installation
  • Utilities: Network info, prerequisites, timing

See ACTIONS.md for complete list.

Parameter Passing

Actions can reference outputs from previous actions, results from actions, and results from tasks:

// Reference action outputfile.NewReplaceLinesAction(
"config.txt",
map[*regexp.Regexp]string{
regexp.MustCompile("{{version}}"):
task_engine.ActionOutput("read-file", "version"),
},
logger,
)
// Reference task outputdocker.NewDockerRunAction(
task_engine.TaskOutput("build", "imageID"),
[]string{"-p", "8080:8080"},
logger,
)
// Reference action result (from an action implementing ResultProvider)useChecksum:=task_engine.ActionResultField("download-artifact", "checksum")
// Reference task result (from a task implementing ResultProvider or using ResultBuilder)preflightMode:=task_engine.TaskResultField("preflight", "UpdateMode")

Task Management

manager:=task_engine.NewTaskManager(logger)
// Add tasks (returns error on duplicate ID or nil task)iferr:=manager.AddTask(task); err!=nil {
logger.Error("Failed to add task", "error", err)
}
// Run tasks — returns a TaskHandle for async trackinghandle, err:=manager.RunTask("my-task-id")
iferr!=nil {
logger.Error("Failed to start task", "error", err)
}
<-handle.Done() // wait for completioniferr:=handle.Err(); err!=nil {
logger.Error("Task failed", "error", err)
}
// Stop tasksmanager.StopTask("my-task-id")
manager.StopAllTasks()

Custom Actions

typeMyActionstruct {
task_engine.BaseActionMessagestring
}
func (a*MyAction) Execute(ctx context.Context) error {
a.Logger.Info("Executing", "message", a.Message)
returnnil
}
funcNewMyAction(messagestring, logger*slog.Logger) *task_engine.Action[*MyAction] {
return&task_engine.Action[*MyAction]{
ID: "my-action",
Wrapped: &MyAction{
BaseAction: task_engine.BaseAction{Logger: logger},
Message: message,
},
}
}

Examples

See tasks/ directory for complete examples:

  • File operations workflow
  • Docker setup and management
  • Package installation
  • Archive extraction

Testing

import"github.com/ndizazzo/task-engine/testing/mocks"mockManager:=mocks.NewEnhancedTaskManagerMock()
mockRunner:=&mocks.MockCommandRunner{}

Documentation

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages