tasks

package
v0.0.0-...-84501ce Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2017 License: GPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	PersistenceWritetrough persistenceType = 0
	PersistenceWriteback   persistenceType = 1
	PersistenceNone        persistenceType = 2
)

Persistence types (must be the same as in queueproto)

View Source
const (
	DeliveryAnyone               deliveryType = 0
	DeliveryEveryone             deliveryType = 1
	DeliveryEveryoneNowAndFuture deliveryType = 2
)

Delivery types (must be the same as in queueproto)

Variables

This section is empty.

Functions

This section is empty.

Types

type Acks

type Acks struct {
	Accepted  bool
	Done      bool
	Timeout   bool
	Aborted   bool
	Dismissed bool
}

Acks is a struct to hold a list of acknowledgements requested for the task

type ForeachFunc

type ForeachFunc func(id string, task *Task) (found bool, stop bool)

ForeachFunc is a type of func to be passed to Foreach method

type StatusType

type StatusType int8

StatusType is a type for the task statuses

const (
	StatusQueued         StatusType = 0
	StatusAccepted       StatusType = 1
	StatusDone           StatusType = 2
	StatusTimedout       StatusType = 3
	StatusAborted        StatusType = 4
	StatusDismissed      StatusType = 5
	StatusDispatched     StatusType = 6
	StatusInProgress     StatusType = 8
	StatusToRemove       StatusType = -1
	StatusAcceptTimeout  StatusType = -2
	StatusProcessTimeout StatusType = -3
)

Status values (must be the same as in queueproto)

type Storage

type Storage struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Storage is a simple RWLock protected map

func NewStorage

func NewStorage() *Storage

NewStorage creates a new task storage struct with the internal map initialised

func (*Storage) Add

func (s *Storage) Add(task *Task)

Add adds task to the sorage

func (*Storage) Del

func (s *Storage) Del(id string)

Del deletes task to the sorage

func (*Storage) Foreach

func (s *Storage) Foreach(f ForeachFunc) int

Foreach executes the function provided for each task in the storage

func (*Storage) Get

func (s *Storage) Get(id string) *Task

Get returns task from the storage

func (*Storage) Restore

func (s *Storage) Restore(task *Task)

Restore adds task to the sorage with respect to the sequence internal variable

type Task

type Task struct {
	Queue       string
	Subject     string
	Originator  string
	Timeout     time.Duration
	Persistence persistenceType
	Delivery    deliveryType
	Ack         Acks
	Payload     []byte
	Status      StatusType
	CTime       time.Time

	Sequence int64
	// contains filtered or unexported fields
}

Task as it will be serialized to DB

func NewTask

func NewTask(protoTask *queueproto.QueueTask) *Task

NewTask builds a task from queueproto.QueueTask. Just in case we will have to change proto and DB scheme independently

func (*Task) ChangeExpire

func (t *Task) ChangeExpire(expire *time.Timer)

ChangeExpire changes the task expire timer

func (*Task) ChangeStatus

func (t *Task) ChangeStatus(status StatusType)

ChangeStatus changes the task status (surprise)

func (*Task) ChangeStatusAndExpire

func (t *Task) ChangeStatusAndExpire(status StatusType, expire *time.Timer)

ChangeStatusAndExpire changes the task status and expire (surprise)

func (*Task) ID

func (t *Task) ID() string

ID returns task id (surprise)

func (*Task) Marshal

func (t *Task) Marshal() []byte

Marshal marshals Task to the JSON bytes

func (*Task) SetID

func (t *Task) SetID(id string)

SetID sets task id (surprise)

Jump to

Keyboard shortcuts

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