runners

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package runners provides abstractions and utilities for working with different runner implementations.

Index

Constants

This section is empty.

Variables

View Source
var Available = map[string]RunnerCreator{
	"go": newGolangRunner,
	"py": newPythonRunner,
}

Available maps runner type strings (like "go" or "py") to their respective RunnerCreator functions. This allows for the dynamic creation of runners based on the runner type.

Functions

This section is empty.

Types

type Part

type Part uint8

Part represents a section or segment of a task or process.

const (
	PartOne   Part = iota + 1 // PartOne is the first part of the exercise.
	PartTwo                   // PartTwo is the second part of the exercise.
	Visualize                 // Visualize is the optional visualization of exercise processing.
)

type Result

type Result struct {
	// TaskID is the unique identifier for the task that produced this result.
	TaskID string `json:"task_id"`
	// Ok indicates whether the task was successful.
	Ok bool `json:"ok"`
	// Output is the output of the task, if successful.
	Output string `json:"output"`
	// Duration is the amount of time it took for the task to complete.
	Duration float64 `json:"duration"`
}

A Result represents the outcome of a Task.

type ResultOrError

type ResultOrError struct {
	Result *Result
	Error  error
}

ResultOrError holds either the result of a task or an error. It is useful for communicating results and errors from asynchronous operations.

type Runner

type Runner interface {
	// Start initializes the runner.
	Start() error
	// Stop terminates the runner.
	Stop() error
	// Cleanup handles any cleanup operations required after running a task.
	Cleanup() error
	// Run executes a given task and returns the result or an error.
	Run(task *Task) (*Result, error)

	String() string
}

Runner is an interface defining methods for starting, stopping, cleaning up, and running tasks.

type RunnerCreator

type RunnerCreator func(dir string) Runner

RunnerCreator is a function type that takes a directory string as input and returns a Runner. This allows for dynamic creation of different types of runners based on the provided directory.

type Task

type Task struct {
	// TaskID is the unique identifier for the task.
	TaskID string `json:"task_id"`

	// Part is the part of the work that the task should perform.
	Part Part `json:"part"`

	// Input is the input data for the task.
	Input string `json:"input"`

	// OutputDir is the directory where the task should store its output.
	// This field is optional.
	OutputDir string `json:"output_dir,omitempty"`
}

A Task represents a unit of work to be performed.

Jump to

Keyboard shortcuts

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