jobs

package
v0.0.0-...-58bd1cf Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobNameUserCsvImport = "UserCsvImport"
	JobNamePetClear      = "PetClear"
	JobNamePetCatCreate  = "PetCatCreate"
	JobNamePetDogCreate  = "PetDogCreate"
)
View Source
const (
	JobChainPetReset = "PetReset"
)

Variables

View Source
var (
	ErrItemSkip = errors.New("item skip")
)
View Source
var ErrJobOverflow = errors.New("Job Overflow")

-----------------------------

Functions

func ArgBind

func ArgBind(c *xin.Context, a any) error

func CleanOutdatedJobChains

func CleanOutdatedJobChains()

CleanOutdatedJobChains iterate schemas to clean outdated job chains

func CleanOutdatedJobs

func CleanOutdatedJobs()

------------------------------------ CleanOutdatedJobs iterate schemas to clean outdated jobs

func JobAbortChain

func JobAbortChain(tjc xjm.JobChainer, jc *xjm.JobChain, jid int64, reason string) (bool, error)

func JobCancelChain

func JobCancelChain(tjc xjm.JobChainer, jc *xjm.JobChain, jid int64, reason string) (bool, error)

func JobChainAbort

func JobChainAbort(tjc xjm.JobChainer, tjm xjm.JobManager, jc *xjm.JobChain, reason string) error

func JobChainAppendJob

func JobChainAppendJob(tt *tenant.Tenant, name, locale string, cid int64, csq int, cdt bool) error

func JobChainCancel

func JobChainCancel(tjc xjm.JobChainer, tjm xjm.JobManager, jc *xjm.JobChain, reason string) error

func JobChainEncodeStates

func JobChainEncodeStates(states []*JobRunState) string

func JobChainStart

func JobChainStart(tt *tenant.Tenant, chainName string, states []*JobRunState, jobName, jobLocale, jobFile string, jobParam IArgChain) (cid int64, err error)

func JobFindAndCancelChain

func JobFindAndCancelChain(tt *tenant.Tenant, cid, jid int64, reason string) error

func JobStatusText

func JobStatusText(js string) string

func ReappendJobs

func ReappendJobs()

------------------------------------

func RegisterJobArg

func RegisterJobArg(name string, jac JobArgCreater)

func RegisterJobRun

func RegisterJobRun(name string, jrc JobRunCreator)

func StartJobs

func StartJobs(tt *tenant.Tenant) error

StartJobs start tenant jobs

func Starts

func Starts()

Starts iterate tenants to start jobs

func Stats

func Stats() string

Types

type ArgChain

type ArgChain struct {
	ChainSeq  int  `json:"chain_seq,omitempty" form:"-"`
	ChainData bool `json:"chain_data,omitempty" form:"chain_data"`
}

func (*ArgChain) GetChain

func (ac *ArgChain) GetChain() (int, bool)

func (*ArgChain) SetChain

func (ac *ArgChain) SetChain(csq int, cdt bool)

func (*ArgChain) ShouldChainData

func (ac *ArgChain) ShouldChainData() bool

type ArgIDRange

type ArgIDRange struct {
	IdFrom int64 `json:"id_from,omitempty" form:"id_from,strip" validate:"min=0"`
	IdTo   int64 `json:"id_to,omitempty" form:"id_to,strip" validate:"omitempty,min=0,gtefield=IdFrom"`
}

type ArgItems

type ArgItems struct {
	Items int `json:"items,omitempty" form:"items,strip" validate:"min=0"`
}

type ArgPeriod

type ArgPeriod struct {
	Start time.Time `json:"start,omitempty" form:"start"`
	End   time.Time `json:"end,omitempty" form:"end" validate:"omitempty,gtefield=Start"`
}

func (*ArgPeriod) Period

func (ap *ArgPeriod) Period() *ArgPeriod

type FailedItem

type FailedItem struct {
	ID    int64  `json:"id"`
	Title string `json:"title"`
	Error string `json:"error"`
}

func (*FailedItem) Quoted

func (si *FailedItem) Quoted() string

func (*FailedItem) String

func (si *FailedItem) String() string

type IArg

type IArg interface {
	Bind(c *xin.Context) error
}

type IArgChain

type IArgChain interface {
	GetChain() (int, bool)
	SetChain(chainSeq int, chainData bool)
}

type IRun

type IRun interface {
	Run()
}

type JobArgCreater

type JobArgCreater func(*tenant.Tenant) IArg

type JobRunCreator

type JobRunCreator func(*tenant.Tenant, *xjm.Job) IRun

type JobRunState

type JobRunState struct {
	JID    int64    `json:"jid"`
	Name   string   `json:"name"`
	Status string   `json:"status"`
	Error  string   `json:"error"`
	State  JobState `json:"state"`
}

func JobChainDecodeStates

func JobChainDecodeStates(state string) (states []*JobRunState)

func JobChainInitStates

func JobChainInitStates(jns ...string) []*JobRunState

type JobRunner

type JobRunner[T any] struct {
	*xjm.JobRunner
	ArgChain

	Tenant *tenant.Tenant
	Logger log.Logger
	Arg    T
}

func NewJobRunner

func NewJobRunner[T any](tt *tenant.Tenant, job *xjm.Job) *JobRunner[T]

func (*JobRunner[T]) Abort

func (jr *JobRunner[T]) Abort(reason string)

func (*JobRunner[T]) AddFailedItem

func (jr *JobRunner[T]) AddFailedItem(id int64, title, reason string)

func (*JobRunner[T]) Checkout

func (jr *JobRunner[T]) Checkout() error

func (*JobRunner[T]) Done

func (jr *JobRunner[T]) Done(err error)

func (*JobRunner[T]) Finish

func (jr *JobRunner[T]) Finish()

func (*JobRunner[T]) Running

func (jr *JobRunner[T]) Running() (context.Context, context.CancelCauseFunc)

func (*JobRunner[T]) SetState

func (jr *JobRunner[T]) SetState(state iState) error

type JobState

type JobState struct {
	Step    int `json:"step,omitempty"`
	Count   int `json:"count,omitempty"`
	Total   int `json:"total,omitempty"`
	Limit   int `json:"limit,omitempty"`
	Exists  int `json:"exists,omitempty"`
	Skipped int `json:"skipped,omitempty"`
	Success int `json:"success,omitempty"`
	Failure int `json:"failure,omitempty"`
}

func (*JobState) Counts

func (js *JobState) Counts() string

func (*JobState) IncFailure

func (js *JobState) IncFailure()

func (*JobState) IncSkipped

func (js *JobState) IncSkipped()

func (*JobState) IncSuccess

func (js *JobState) IncSuccess()

func (*JobState) IsStepLimited

func (js *JobState) IsStepLimited() bool

func (*JobState) Progress

func (js *JobState) Progress() string

func (*JobState) SetTotalLimit

func (js *JobState) SetTotalLimit(total, limit int)

func (*JobState) State

func (js *JobState) State() JobState

type JobStateEx

type JobStateEx struct {
	JobState
	LastID int64 `json:"last_id,omitempty"`
}

type JobStateFsx

type JobStateFsx struct {
	JobStateSx
	LastID        int64     `json:"last_id,omitempty"`
	LastUpdatedAt time.Time `json:"last_updated_at,omitempty"`
}

type JobStateSx

type JobStateSx struct {
	JobState
}

func (*JobStateSx) IncFailure

func (js *JobStateSx) IncFailure()

func (*JobStateSx) IncSkipped

func (js *JobStateSx) IncSkipped()

func (*JobStateSx) IncSuccess

func (js *JobStateSx) IncSuccess()

func (*JobStateSx) IsSuccessLimited

func (js *JobStateSx) IsSuccessLimited() bool

func (*JobStateSx) Progress

func (js *JobStateSx) Progress() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳