astiworker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2018 License: MIT Imports: 12 Imported by: 0

README

Worker

// Init worker
var w = astiworker.NewWorker()

// Handle signals
w.HandleSignals()

// Serve
w.Serve("127.0.0.1:4000", myHandler)

// Execute
h, _ := w.Exec("sleep", "10")
go func() {
	time.Sleep(3 * time.Second)
	h.Stop()
}

// Wait
w.Wait()

Documentation

Index

Constants

View Source
const (
	ExecHandlerStatusCrashed = "crashed"
	ExecHandlerStatusRunning = "running"
	ExecHandlerStatusStopped = "stopped"
)

Statuses

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigurationConsumer

type ConfigurationConsumer struct {
	AMQP        astiamqp.ConfigurationConsumer
	WorkerCount int
}

ConfigurationConsumer represents a consumer configuration

type ExecHandler

type ExecHandler interface {
	Status() string
	Stop()
}

ExecHandler represents an object capable of handling the execution of a cmd

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task represents a task

func (*Task) Done

func (t *Task) Done()

Done indicates the task is done

func (*Task) NewSubTask

func (t *Task) NewSubTask() *Task

NewSubTask creates a new sub task

func (*Task) Wait

func (t *Task) Wait()

Wait waits for the task to be finished

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker represents an object capable of blocking, handling signals and stopping

func NewWorker

func NewWorker() (w *Worker)

NewWorker builds a new worker

func (*Worker) Consume

func (w *Worker) Consume(a *astiamqp.AMQP, cs ...ConfigurationConsumer) (err error)

Consume consumes AMQP events

func (*Worker) Context

func (w *Worker) Context() context.Context

Context returns the worker's context

func (*Worker) Exec

func (w *Worker) Exec(name string, args ...string) (ExecHandler, error)

Exec executes a cmd The process will be stopped when the worker stops

func (*Worker) HandleSignals

func (w *Worker) HandleSignals()

HandleSignals handles signals

func (*Worker) NewTask

func (w *Worker) NewTask() *Task

NewTask creates a new task

func (*Worker) Serve

func (w *Worker) Serve(addr string, h http.Handler)

Serve spawns a server

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops the Worker

func (*Worker) Wait

func (w *Worker) Wait()

Wait is a blocking pattern

Jump to

Keyboard shortcuts

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