exeggcutor

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 7 Imported by: 0

README

Exeggcutor

Lightweight, no dependency, concurrent executor for running tasks.

Disclaimer

This is a work in progress and is not yet ready for production use. Its mostly used to learn about concurrency in Golang.

Usage

package main

import (
    "time"
    "github.com/haftcl/exeggcutor"
)

// The hydrator interface is used to hydrate the executor with tasks that implements the Runner interface
type HydratorImpl struct {
}

// The runner interface is used to define the task to be executed
type RunnerImpl struct {
}

// Implement the interfaces
func (r *RunnerImpl) Execute(ctx context.Context) error {
    time.Sleep(time.Duration(100) * time.Millisecond)
    return nil
}

func (h *HydratorImpl) Get(ctx context.Context) ([]Runner, error) {
	runners := make([]Runner, 0)
	runners = append(runners, &RunnerImpl{})
	return runners, nil
}

func main() {
    // Create a new hydrator
    h := HydratorImpl{}
    // Create a new exeggcutor
    e := exeggcutor.New(h, 1000, nil, 1)
    // Run the executor
    e.Start(context.Background())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor added in v0.0.5

type Executor struct {
	ExitOnError bool
	// contains filtered or unexported fields
}

Executor is the main struct that will execute the hydration and running of the jobs.

func New

func New(hydrator Hydrator, timeOutInMs int, logger *slog.Logger, numWorkers int) *Executor

New creates a new Executor instance thats ready to use.

func (*Executor) Start added in v0.0.5

func (e *Executor) Start(ctx context.Context)

Start the executions of the tasks

type Hydrator

type Hydrator interface {
	Get(context.Context) ([]Runner, error)
}

Hydrator is an interface that defines the methods to obtain the jobs

type Runner

type Runner interface {
	Execute(context.Context) error
}

Runner is an interface that defines the methods to execute a job

Jump to

Keyboard shortcuts

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