executor

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSystemContext

func NewSystemContext() context.Context

func StartExecution

func StartExecution(ctx context.Context, cfg Config) error

StartExecution initializes and manages the execution of tasks based on the provided configuration. It validates the configuration, spawns worker goroutines, and processes tasks in batches.

Parameters:

  • ctx: A context.Context object used to manage the lifecycle of the execution process.
  • cfg: A Config object containing the execution parameters such as parallelism, batch size, command, and more.

Returns:

  • error: Returns an error if the configuration is invalid or if the execution is prematurely terminated.

Behavior:

  • Validates the provided configuration. If invalid, logs the error and terminates.
  • Creates a channel for execution requests and spawns worker goroutines based on the configured parallelism.
  • Processes tasks in batches, sending execution requests to the worker goroutines.
  • Monitors the context for cancellation and ensures proper cleanup of resources.
  • Waits for all worker goroutines to complete before returning.

Notes:

  • The function ensures that the request channel is closed properly after use.
  • If the context is canceled before completion, an error is returned, and the process is terminated.

Types

type Config

type Config struct {
	Shell     string
	ShellArgs []string

	Command          string
	WorkingDirectory string
	StdIn            string

	Limit     int
	Offset    int
	BatchSize int

	Timeout  time.Duration
	Parallel int

	LogDir      string
	LogToStdErr bool
}

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the Config for any invalid or missing fields.

type ExecRequest

type ExecRequest struct {
	Command   string
	StdIn     string
	Offset    int
	BatchSize int

	Shell            string
	ShellArgs        []string
	WorkingDirectory string

	Timeout time.Duration
	// contains filtered or unexported fields
}

ExecRequest represents a request to execute a command with specific parameters. It contains configuration options for the execution environment, command details, and logging preferences.

Fields: - rootCtx: The root context for the execution, used for cancellation and deadlines. - Command: The command to be executed. - Offset: The starting offset for processing, if applicable. - BatchSize: The size of the batch to process, if applicable. - Shell: The shell to use for executing the command. - ShellArgs: Additional arguments to pass to the shell. - WorkingDirectory: The directory in which the command should be executed. - Timeout: The maximum duration allowed for the command execution. - logRoot: The root directory for storing logs. - logToErr: A flag indicating whether logs should also be written to stderr.

Jump to

Keyboard shortcuts

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