Categorygithub.com/DanLavine/goasync
modulepackage
2.0.0+incompatible
Repository: https://github.com/danlavine/goasync.git
Documentation: pkg.go.dev

# README

GoAsync - Flexible processes management library

godoc

Go Async is designed to simplify managing multi-process applications into easily understandable single purpose units of work.

The Task Manager is responsible for running and managing any number of assigned tasks. For the Task Manager to operate, each task must follow 1 of two patterns.

Long Running Task

These tasks are expected to run for the entire task manager lifecyle as they have special initialization and shutdown logic.

  1. Each task added to the Task Manager will initialize serially in the order they were added to the Task Manager
    1. If an error occurs during Initialization, any remaining tasks are skipped and Cleanup is called for any tasks that have already been Initialized
  2. In parallel runs all Execute(...) functions for any tasks
    1. If the task manager is configured to abort execution on any stoped task, then the Task Manager will cancel all running tasks and then run the Cleanup for each task.
  3. When the Task Manager's context is canceled, each task process will have their context canceled. The task manager will then wait until all running tasks have been stopped.
  4. Each Task's Cleanup function is called in reverse order they were added to the Task Manager

Task interface:

// Task is anything that can be added to the TaskManager before it stats Executing.
type Task interface {
// Initialize functions are ran serially in the order they were added to the TaskManager.
// These are useful when one Goroutine dependency requires a previous Worker to setup some common
// dependency like a DB connection.
Initialize() error

// Execute is the main Async function to house all the multi-threaded logic handled by GoAsync.
Execute(ctx context.Context) error

// Cleanup functions are ran serially in reverse order they were added to the TaskManager.
// This way the 1st Initalized dependency is stopped last
Cleanup() error
}

Execute Task

Can be added to a process that is already running

ExecuteTask interface:

// ExecuteTask can be added to the TaskManager before or after it has already started Executing the tasks.
// These tasks are expected to already be properly Initialized and don't require any Cleanup Code.
type ExecuteTask interface {
  // Execute is the main Async function to house all the multi-threaded logic handled by GoAsync.
  Execute(ctx context.Context) error
}

Provided tasks

For a number of common basic tasks provided, see tasks directory

Installation

go get -u github.com/DanLavine/goasync

Examples

For a few simple and basic real world example check out the internal/examples dir

Running tests

To run all tests:

go test --race ./...

If we want to run one specific test we can use:

go test --race -run [NAME OF TEST] ./...

To ignore the test cache:

go test --race -count=1 ./...

# Packages

Code generated by counterfeiter.
No description provided by the author

# Functions

PARAMETERS: - config - configuration to use.

# Constants

No description provided by the author
No description provided by the author
ERROR will cause a shutdown to all other tasks if any non nil error is returned before the Task Manager's Context has been canceled.
STRICT will cause a shutdown to all other tasks if they return before the Task Manager's Context has been canceled.
No description provided by the author
ERROR will cause a shutdown to all other tasks if any non nil error is returned before the Task Manager's Context has been canceled.
STOP_GROUP will cause a shutdown on the Task Manager once all STOP_GROUP process have finished iff they only return nil error(s).
STRICT will cause a shutdown to all other tasks if they return before the Task Manager's Context has been canceled.

# Structs

No description provided by the author
TaskManager implements the AsyncTaskManager interface and contains the logic for managing any Tasks proovided to this struct.

# Interfaces

AsyncTaskManager manages any number of tasks counterfeiter:generate .
ExecuteTask can be added to the TaskManager before or after it has already started Executing the tasks.
Task is anything that can be added to the TaskManager before it stats Executing.

# Type aliases

EXECUTE_TASK_TYPE defines the possible task types that can applied to an already running Task Manager.
No description provided by the author
TASK_TYPE defines how tasks should be handeled when they stop processing.