AFAIRE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.3 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "time"
type Job struct {
ID string `json:"id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Type string `json:"type"`
Origin string `json:"origin"`
Priority Priority `json:"priority"`
Public map[string]interface{} `json:"public"`
Private map[string]interface{} `json:"private"`
RunAfter time.Time `json:"run_after"`
Exclusivity Exclusivity `json:"exclusivity"`
MaxOccurences int `json:"max_occurences"`
MaxAttempts int `json:"max_attempts"`
Category *string `json:"category"`
Workflow *string `json:"workflow"`
CreatedAt time.Time `json:"created_at"`
Status Status `json:"status"`
Attempt int `json:"attempt"`
Session int `json:"session"`
Result *Result `json:"result"`
FinishedAt *time.Time `json:"finished_at"`
TimeReference time.Time `json:"time_reference"`
}
func NewJob(namespace, _type string) *Job {
return &Job{
Namespace: namespace,
Type: _type,
}
}
func (job *Job) SetID(value string) *Job {
job.ID = value
return job
}
func (job *Job) SetName(value string) *Job {
job.Name = value
return job
}
func (job *Job) SetOrigin(value string) *Job {
job.Origin = value
return job
}
func (job *Job) SetPriority(value Priority) *Job {
job.Priority = value
return job
}
func (job *Job) SetPriorityNone() *Job {
return job.SetPriority(PriorityNone)
}
func (job *Job) SetPriorityLow() *Job {
return job.SetPriority(PriorityLow)
}
func (job *Job) SetPriorityMedium() *Job {
return job.SetPriority(PriorityMedium)
}
func (job *Job) SetPriorityHigh() *Job {
return job.SetPriority(PriorityHigh)
}
func (job *Job) SetPriorityCritical() *Job {
return job.SetPriority(PriorityCritical)
}
func (job *Job) SetPublic(key string, value interface{}) *Job {
if job.Public == nil {
job.Public = make(map[string]interface{})
}
job.Public[key] = value
return job
}
func (job *Job) SetPrivate(key string, value interface{}) *Job {
if job.Private == nil {
job.Private = make(map[string]interface{})
}
job.Private[key] = value
return job
}
func (job *Job) SetRunAfter(value time.Time) *Job {
job.RunAfter = value
return job
}
func (job *Job) SetExclusivity(value Exclusivity) *Job {
job.Exclusivity = value
return job
}
func (job *Job) SetExclusivityNo() *Job {
return job.SetExclusivity(ExclusivityNo)
}
func (job *Job) SetExclusivityItself() *Job {
return job.SetExclusivity(ExclusivityItself)
}
func (job *Job) SetExclusivityNamespace() *Job {
return job.SetExclusivity(ExclusivityNamespace)
}
func (job *Job) SetMaxOccurences(value int) *Job {
job.MaxOccurences = value
return job
}
func (job *Job) SetMaxAttempts(value int) *Job {
job.MaxAttempts = value
return job
}
func (job *Job) SetCategory(value string) *Job {
category := new(string)
*category = value
job.Category = category
return job
}
func (job *Job) Fields() []interface{} {
var (
category interface{}
workflow interface{}
)
if job.Category != nil {
category = *job.Category
}
if job.Workflow != nil {
workflow = *job.Workflow
}
return []interface{}{
"id", job.ID,
"name", job.Name,
"namespace", job.Namespace,
"type", job.Type,
"origin", job.Origin,
"priority", job.Priority,
"run_after", job.RunAfter,
"exclusivity", job.Exclusivity,
"max_occurences", job.MaxOccurences,
"max_attempts", job.MaxAttempts,
"category", category,
"workflow", workflow,
}
}
func (job *Job) Finished(status Status) {
now := new(time.Time)
*now = time.Now()
job.Status = status
job.FinishedAt = now
}
/*
######################################################################################################## @(°_°)@ #######
*/