Gestionnaire de jobs et workflows
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.
dune/internal/storage/memory/workflows.go

114 lines
2.7 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package memory
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/dune/internal/storage"
)
func (ms *memoryStorage) findWorkflow(id string) (int, *jw.Workflow) {
for i, wf := range ms.workflows {
if wf.ID == id {
return i, wf
}
}
return 0, nil
}
func (ms *memoryStorage) ValidateWorkflow(_ *jw.Workflow) error {
return nil
}
func (ms *memoryStorage) InsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
ms.sm.Lock()
defer ms.sm.Unlock()
if _, w := ms.findWorkflow(wf.ID); w != nil {
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////////
storage.ErrStorage,
errors.New("this workflow identifier already exists", "id", wf.ID),
)
}
if _, err := ms.insertJob(job); err != nil {
return err
}
ms.workflows = append(ms.workflows, wf)
return nil
}
func (ms *memoryStorage) Workflow(id string, mustExist bool) (*jw.Workflow, error) {
ms.sm.Lock()
defer ms.sm.Unlock()
if _, wf := ms.findWorkflow(id); wf != nil {
return wf, nil
}
if mustExist {
return nil, errors.New("this workflow does not exist", "id", id) ///////////////////////////////////////////////
}
return nil, nil
}
func (ms *memoryStorage) UpdateWorkflow(wf *jw.Workflow, job, nextJob *jw.Job) error {
ms.sm.Lock()
defer ms.sm.Unlock()
if err := ms.updateJob(job); err != nil {
return err
}
if wf != nil {
i, w := ms.findWorkflow(wf.ID)
if w == nil {
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////
storage.ErrStorage,
errors.New("this workflow does not exist", "wf", wf.ID),
)
}
ms.workflows[i] = wf
}
if nextJob == nil {
return nil
}
_, err := ms.insertJob(nextJob)
return err
}
func (ms *memoryStorage) SetWorkflowPriority(id string, priority jw.Priority) error {
ms.sm.Lock()
defer ms.sm.Unlock()
_, wf := ms.findWorkflow(id)
if wf == nil {
return errors.New("this workflow does not exist", "workflow", id) //////////////////////////////////////////////
}
if wf.FinishedAt != nil {
return errors.New("this workflow is finished", "workflow", id) /////////////////////////////////////////////////
}
wf.Priority = priority
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/