job

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body string

Body job body

func (Body) IsEmpty

func (b Body) IsEmpty() bool

IsEmpty body is empty

type Delay

type Delay time.Duration

Delay job delay time

func (Delay) IsEmpty

func (d Delay) IsEmpty() bool

IsEmpty delay is empty

type Empty

type Empty interface {
	IsEmpty() bool
}

Empty interface

type ID

type ID string

ID job ID

func (ID) IsEmpty

func (id ID) IsEmpty() bool

IsEmpty id is empty

type Job

type Job struct {
	Topic   Topic       `json:"topic,omitempty"`
	ID      ID          `json:"id,omitempty"`
	Delay   Delay       `json:"delay,omitempty"`
	TTR     TTR         `json:"ttr,omitempty"`
	Body    Body        `json:"body,omitempty"`
	Version Version     `json:"version,omitempty"`
	Mutex   lock.Locker `json:"-"`
}

Job job for delay queue

func Get

func Get(topic Topic, id ID, lockerFunc lock.LockerFunc) (*Job, error)

Get a job entity before load all information from storage

func New

func New(topic Topic, id ID, delay Delay, ttr TTR, body Body, lockerFunc lock.LockerFunc) (*Job, error)

New return a job with everything init

func (*Job) GetDelayTimeFromNow

func (j *Job) GetDelayTimeFromNow() time.Time

GetDelayTimeFromNow return how much time to wait for delaying

func (*Job) GetName

func (j *Job) GetName() string

GetName return job unique name getter

func (*Job) GetNameWithVersion

func (j *Job) GetNameWithVersion() NameVersion

GetNameWithVersion return name version of job

func (*Job) GetTTRTimeFromNow

func (j *Job) GetTTRTimeFromNow() time.Time

GetTTRTimeFromNow return how much time to wait until overtime

func (*Job) IsValid

func (j *Job) IsValid() error

IsValid check job is valid. job is not nil and topic and id is not empty

func (*Job) IsVersionSame

func (j *Job) IsVersionSame(v Version) bool

IsVersionSame return whether j's version is equal to v

func (*Job) Lock

func (j *Job) Lock() error

Lock lock the job

func (*Job) SetVersion

func (j *Job) SetVersion(ts int64)

SetVersion set job version by nano ts

func (*Job) Unlock

func (j *Job) Unlock() (bool, error)

Unlock unlock the job

type NameVersion

type NameVersion string

NameVersion name version, combination of topic, id and version

func NewNameVersion

func NewNameVersion(topic Topic, id ID, version Version) NameVersion

NewNameVersion create new name version object

func NewNameVersionString

func NewNameVersionString(str string) NameVersion

NewNameVersionString convert string to name version

func (NameVersion) MarshalBinary

func (nv NameVersion) MarshalBinary() ([]byte, error)

MarshalBinary for json encode

func (NameVersion) Parse

func (nv NameVersion) Parse() (Topic, ID, Version, error)

Parse parse name version to topic, id and version

type TTR

type TTR time.Duration

TTR job time to run

func (TTR) IsEmpty

func (t TTR) IsEmpty() bool

IsEmpty ttr is empty

type Topic

type Topic string

Topic job topic

func (Topic) IsEmpty

func (t Topic) IsEmpty() bool

IsEmpty topic is empty

type Version

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

Version job version, it is a time object. nano timestamp

func LoadVersion

func LoadVersion(vs string) (Version, error)

LoadVersion load version from a string

func NewVersion

func NewVersion() Version

NewVersion create a new version

func (Version) Equal

func (v Version) Equal(v2 Version) bool

Equal check version v equals to version v2

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

MarshalJSON json marshall

func (Version) String

func (v Version) String() string

String function

func (Version) UInt64

func (v Version) UInt64() uint64

UInt64 function

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(b []byte) error

UnmarshalJSON json unmarshall

Jump to

Keyboard shortcuts

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