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.

132 lines
3.3 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "time"
type Step struct {
Namespace string `json:"namespace"`
Type string `json:"type"`
Config map[string]interface{} `json:"config"`
Exclusivity Exclusivity `json:"exclusivity"`
MaxOccurences int `json:"max_occurences"`
MaxAttempts int `json:"max_attempts"`
Next map[string]interface{} `json:"next"`
}
type Workflow struct {
ID string `json:"id"`
Type string `json:"type"`
Description string `json:"description"`
Origin string `json:"origin"`
Priority Priority `json:"priority"`
FirstStep string `json:"first_step"`
AllSteps map[string]*Step `json:"all_steps"`
Data map[string]interface{} `json:"data"`
ExternalID *string `json:"external_id"`
CreatedAt time.Time `json:"created_at"`
Status Status `json:"status"`
FinishedAt *time.Time `json:"finished_at"`
}
func NewWorkflow(firstStep string, allSteps map[string]*Step) *Workflow {
return &Workflow{
FirstStep: firstStep,
AllSteps: allSteps,
}
}
func (wf *Workflow) SetID(value string) *Workflow {
wf.ID = value
return wf
}
func (wf *Workflow) SetType(value string) *Workflow {
wf.Type = value
return wf
}
func (wf *Workflow) SetDescription(value string) *Workflow {
wf.Description = value
return wf
}
func (wf *Workflow) SetOrigin(value string) *Workflow {
wf.Origin = value
return wf
}
func (wf *Workflow) SetPriority(value Priority) *Workflow {
wf.Priority = value
return wf
}
func (wf *Workflow) SetPriorityNone() *Workflow {
return wf.SetPriority(PriorityNone)
}
func (wf *Workflow) SetPriorityLow() *Workflow {
return wf.SetPriority(PriorityLow)
}
func (wf *Workflow) SetPriorityMedium() *Workflow {
return wf.SetPriority(PriorityMedium)
}
func (wf *Workflow) SetPriorityHigh() *Workflow {
return wf.SetPriority(PriorityHigh)
}
func (wf *Workflow) SetPriorityCritical() *Workflow {
return wf.SetPriority(PriorityCritical)
}
func (wf *Workflow) SetData(key string, value interface{}) *Workflow {
if wf.Data == nil {
wf.Data = make(map[string]interface{})
}
wf.Data[key] = value
return wf
}
func (wf *Workflow) SetExternalID(value string) *Workflow {
eID := new(string)
*eID = value
wf.ExternalID = eID
return wf
}
func (wf *Workflow) Fields() []interface{} {
var externalID interface{}
if wf.ExternalID != nil {
externalID = *wf.ExternalID
}
return []interface{}{
"id", wf.ID,
"type", wf.Type,
"description", wf.Description,
"origin", wf.Origin,
"priority", wf.Priority,
"external_id", externalID,
}
}
func (wf *Workflow) Finished() {
now := new(time.Time)
*now = time.Now()
wf.FinishedAt = now
}
/*
######################################################################################################## @(°_°)@ #######
*/