Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
7881f15ef6
  1. 120
      internal/model/workflows.go

120
internal/model/workflows.go

@ -81,8 +81,126 @@ func (m *Model) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
return wf, nil
}
func (m *Model) nextStepAdvanced(step string, value interface{}) (string, map[string]interface{}, error) {
switch next := value.(type) {
case nil:
return "", nil, nil
case string:
return next, nil, nil
case map[string]interface{}:
vs, ok := next["step"]
if !ok {
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////////
"'step' key is missing in this step",
"step", step,
)
}
switch label := vs.(type) {
case nil:
return "", nil, nil
case string:
vd, ok := next["data"]
if !ok {
return label, nil, nil
}
switch data := vd.(type) {
case nil:
return label, nil, nil
case map[string]interface{}:
return label, data, nil
default:
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////
"'data' key is not valid in this step",
"step", step,
)
}
default:
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////////
"'step' key is not valid in this step",
"step", step,
)
}
default:
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////
"configuration of this step is not valid",
"step", step,
)
}
}
func (m *Model) nextStep(wf *jw.Workflow, job *jw.Job) (string, map[string]interface{}, error) {
jr := job.Result
if jr.NextStep != "" {
return jr.NextStep, nil, nil
}
step, ok := wf.AllSteps[job.Name]
if !ok {
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////
"unable to find this step",
"step", job.Name,
)
}
if step.Next == nil {
return "", nil, nil
}
for _, v := range []string{jr.Value, string(job.Status)} {
if v == "" {
continue
}
value, ok := step.Next[v]
if !ok {
continue
}
return m.nextStepAdvanced(job.Name, value)
}
return "", nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////////
"unable to find the next step of this step",
"step", job.Name,
)
}
func (m *Model) nextJob(wf *jw.Workflow, job *jw.Job, stepName string, data map[string]interface{}) (*jw.Job, error) {
nextJob, err := m.stepToJob(wf, stepName)
if err != nil {
return nil, err
}
nextJob.Public = job.Public
util.CopyKV(data, nextJob.Private)
return nextJob, nil
}
func (m *Model) updateWorkflow(wf *jw.Workflow, job *jw.Job) error {
return nil
stepName, data, err := m.nextStep(wf, job)
if err != nil {
return err
}
if stepName == "" {
wf.Status = jw.StatusSucceeded
wf.Finished()
return m.storeWorkflow(wf, job, nil)
}
nextJob, err := m.nextJob(wf, job, stepName, data)
if err != nil {
return err
}
return m.storeWorkflow(nil, job, nextJob)
}
func (m *Model) SetWorkflowPriority(id string, priority jw.Priority) error {

Loading…
Cancel
Save