go-workers: github.com/kihamo/go-workers Index | Files | Directories

package workers

import "github.com/kihamo/go-workers"

Index

Package Files

context.go dispatcher.go dispatcher_status_enumer.go event.go listener.go main.go manager.go manager_item.go metadata.go status.go status_item.go task.go task_status_enumer.go ticker.go utils.go worker.go worker_status_enumer.go

Variables

var (
    EventAll                     = event.NewBaseEvent("All")
    EventDispatcherStatusChanged = event.NewBaseEvent("DispatcherStatusChanged")
    EventWorkerAdd               = event.NewBaseEvent("WorkerAdd")
    EventWorkerRemove            = event.NewBaseEvent("WorkerRemove")
    EventWorkerExecuteStart      = event.NewBaseEvent("WorkerExecuteStart")
    EventWorkerExecuteStop       = event.NewBaseEvent("WorkerExecuteStop")
    EventWorkerStatusChanged     = event.NewBaseEvent("WorkerStatusChanged")
    EventTaskAdd                 = event.NewBaseEvent("TaskAdd")
    EventTaskRemove              = event.NewBaseEvent("TaskRemove")
    EventTaskExecuteStart        = event.NewBaseEvent("TaskExecuteStart")
    EventTaskExecuteStop         = event.NewBaseEvent("TaskExecuteStop")
    EventTaskStatusChanged       = event.NewBaseEvent("TaskStatusChanged")
    EventListenerAdd             = event.NewBaseEvent("ListenerAdd")
    EventListenerRemove          = event.NewBaseEvent("ListenerRemove")
)

func AttemptFromContext Uses

func AttemptFromContext(ctx context.Context) (int64, bool)

func FunctionName Uses

func FunctionName(f interface{}) string

func NewContextWithAttempt Uses

func NewContextWithAttempt(ctx context.Context, attempt int64) context.Context

type Dispatcher Uses

type Dispatcher interface {
    Context() context.Context
    Run() error
    Cancel() error
    Status() DispatcherStatus
    Metadata() Metadata

    AddWorker(Worker) error
    RemoveWorker(Worker)
    GetWorkerMetadata(string) Metadata
    GetWorkers() []Worker

    AddTask(Task) error
    RemoveTask(Task)
    GetTaskMetadata(string) Metadata
    GetTasks() []Task

    AddListener(Event, Listener) error
    RemoveListener(Event, Listener)
    GetListenerMetadata(string) Metadata
    GetListeners() []Listener
}

type DispatcherStatus Uses

type DispatcherStatus int64
const (
    DispatcherStatusUndefined DispatcherStatus = iota
    DispatcherStatusWait
    DispatcherStatusProcess
    DispatcherStatusCancel
)

func DispatcherStatusString Uses

func DispatcherStatusString(s string) (DispatcherStatus, error)

DispatcherStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func DispatcherStatusValues Uses

func DispatcherStatusValues() []DispatcherStatus

DispatcherStatusValues returns all values of the enum

func (DispatcherStatus) Int64 Uses

func (i DispatcherStatus) Int64() int64

func (DispatcherStatus) IsADispatcherStatus Uses

func (i DispatcherStatus) IsADispatcherStatus() bool

IsADispatcherStatus returns "true" if the value is listed in the enum definition. "false" otherwise

func (DispatcherStatus) String Uses

func (i DispatcherStatus) String() string

type Event Uses

type Event interface {
    fmt.Stringer
    fmt.GoStringer

    Id() string
    Name() string
}

type Listener Uses

type Listener interface {
    Run(context.Context, Event, time.Time, ...interface{})
    Id() string
    Name() string
}

type ListenerWithEvents Uses

type ListenerWithEvents interface {
    Listener

    Events() []Event
}

type Manager Uses

type Manager interface {
    Push(ManagerItem) error
    Pull() ManagerItem
    Remove(ManagerItem)
    GetById(string) ManagerItem
    GetAll() []ManagerItem
}

type ManagerItem Uses

type ManagerItem interface {
    sync.Locker
    StatusItem

    IsLocked() bool

    Id() string
    Metadata() Metadata
}

type ManagerItemBase Uses

type ManagerItemBase struct {
    StatusItemBase
    // contains filtered or unexported fields
}

func (*ManagerItemBase) IsLocked Uses

func (i *ManagerItemBase) IsLocked() bool

func (*ManagerItemBase) Lock Uses

func (i *ManagerItemBase) Lock()

func (*ManagerItemBase) Metadata Uses

func (i *ManagerItemBase) Metadata() Metadata

func (*ManagerItemBase) Unlock Uses

func (i *ManagerItemBase) Unlock()

type Metadata Uses

type Metadata map[MetadataKey]interface{}

type MetadataKey Uses

type MetadataKey int64
const (
    WorkerMetadataStatus MetadataKey = iota
    WorkerMetadataTask
    WorkerMetadataLocked
)
const (
    TaskMetadataStatus MetadataKey = iota
    TaskMetadataAttempts
    TaskMetadataAllowStartAt
    TaskMetadataFirstStartedAt
    TaskMetadataLastStartedAt
    TaskMetadataLocked
)
const (
    ListenerMetadataFires MetadataKey = iota
    ListenerMetadataFirstFiredAt
    ListenerMetadataLastFireAt
    ListenerMetadataEvents
)
const (
    DispatcherMetadataStatus MetadataKey = iota
)

type Status Uses

type Status interface {
    Int64() int64
    String() string
}

type StatusItem Uses

type StatusItem interface {
    Status() Status
    SetStatus(Status)
    IsStatus(Status) bool
}

type StatusItemBase Uses

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

func (*StatusItemBase) IsStatus Uses

func (i *StatusItemBase) IsStatus(status Status) bool

func (*StatusItemBase) SetStatus Uses

func (i *StatusItemBase) SetStatus(status Status)

func (*StatusItemBase) StatusInt64 Uses

func (i *StatusItemBase) StatusInt64() int64

type Task Uses

type Task interface {
    Run(context.Context) (interface{}, error)
    Id() string
    Name() string
    // приоритет выполения, чем меньше значение тем приоритетнее в очереди задач
    Priority() int64
    Repeats() int64
    // интервал между повторениями
    RepeatInterval() time.Duration
    // таймаут на выполнения задачи
    Timeout() time.Duration
    CreatedAt() time.Time
    // для отложенного запуска
    StartedAt() *time.Time
}

type TaskStatus Uses

type TaskStatus int64
const (
    TaskStatusUndefined TaskStatus = iota
    TaskStatusWait
    TaskStatusProcess
    TaskStatusSuccess
    TaskStatusFail
    TaskStatusRepeatWait
    TaskStatusCancel
)

func TaskStatusString Uses

func TaskStatusString(s string) (TaskStatus, error)

TaskStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TaskStatusValues Uses

func TaskStatusValues() []TaskStatus

TaskStatusValues returns all values of the enum

func (TaskStatus) Int64 Uses

func (i TaskStatus) Int64() int64

func (TaskStatus) IsATaskStatus Uses

func (i TaskStatus) IsATaskStatus() bool

IsATaskStatus returns "true" if the value is listed in the enum definition. "false" otherwise

func (TaskStatus) String Uses

func (i TaskStatus) String() string

type Ticker Uses

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

func NewTicker Uses

func NewTicker(d time.Duration) *Ticker

func (*Ticker) C Uses

func (t *Ticker) C() <-chan time.Time

func (*Ticker) IsStart Uses

func (t *Ticker) IsStart() bool

func (*Ticker) SetDuration Uses

func (t *Ticker) SetDuration(d time.Duration)

func (*Ticker) Start Uses

func (t *Ticker) Start()

func (*Ticker) Stop Uses

func (t *Ticker) Stop()

type Worker Uses

type Worker interface {
    RunTask(context.Context, Task) (interface{}, error)
    Id() string
    CreatedAt() time.Time
}

type WorkerStatus Uses

type WorkerStatus int64
const (
    WorkerStatusUndefined WorkerStatus = iota
    WorkerStatusWait
    WorkerStatusProcess
    WorkerStatusCancel
)

func WorkerStatusString Uses

func WorkerStatusString(s string) (WorkerStatus, error)

WorkerStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func WorkerStatusValues Uses

func WorkerStatusValues() []WorkerStatus

WorkerStatusValues returns all values of the enum

func (WorkerStatus) Int64 Uses

func (i WorkerStatus) Int64() int64

func (WorkerStatus) IsAWorkerStatus Uses

func (i WorkerStatus) IsAWorkerStatus() bool

IsAWorkerStatus returns "true" if the value is listed in the enum definition. "false" otherwise

func (WorkerStatus) String Uses

func (i WorkerStatus) String() string

Directories

PathSynopsis
dispatcher
event
listener
manager
task
worker

Package workers imports 10 packages (graph) and is imported by 37 packages. Updated 2020-11-27. Refresh now. Tools for package owners.