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.
66 lines
1.8 KiB
66 lines
1.8 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package storage |
|
|
|
import ( |
|
"time" |
|
|
|
"forge.chapril.org/dune/jw" |
|
"forge.chapril.org/losyme/errors" |
|
) |
|
|
|
const ErrStorage = errors.Sentinel("storage error") |
|
|
|
type JobsRunning map[string]int |
|
|
|
type JobsToRun interface { |
|
Next() (*jw.Job, error) |
|
} |
|
|
|
type SelectNextJob func(jr JobsRunning, jtr JobsToRun) (*jw.Job, error) |
|
|
|
type State struct { |
|
Jobs struct { |
|
Todo int `json:"todo"` |
|
Pending int `json:"pending"` |
|
Running int `json:"running"` |
|
Succeeded int `json:"succeeded"` |
|
Failed int `json:"failed"` |
|
Total int `json:"total"` |
|
} |
|
Workflows struct { |
|
Running int `json:"running"` |
|
Succeeded int `json:"succeeded"` |
|
Failed int `json:"failed"` |
|
Total int `json:"total"` |
|
} |
|
} |
|
|
|
type Storage interface { |
|
ValidateJob(job *jw.Job) error |
|
InsertJob(job *jw.Job) (bool, error) |
|
UpdateJob(job *jw.Job) error |
|
NotifyJob(id string, data interface{}) error |
|
SetJobPriority(id string, priority jw.Priority) error |
|
SetJobRunAfter(id string, duration time.Duration) error |
|
|
|
NextJob(namespace string, fn SelectNextJob) (*jw.Job, error) |
|
|
|
ValidateWorkflow(wf *jw.Workflow) error |
|
InsertWorkflow(wf *jw.Workflow, job *jw.Job) error |
|
Workflow(id string, mustExist bool) (*jw.Workflow, error) |
|
UpdateWorkflow(wf *jw.Workflow, job, nextJob *jw.Job) error |
|
SetWorkflowPriority(id string, priority jw.Priority) error |
|
|
|
Purge() error |
|
State() (*State, error) |
|
Close() error |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|