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/memory.go

75 lines
1.6 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package memory
import (
"sync"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/dune/internal/storage"
)
type memoryStorage struct {
sm sync.Mutex
jobs []*jw.Job
workflows []*jw.Workflow
}
func New() storage.Storage {
return &memoryStorage{
jobs: make([]*jw.Job, 0),
workflows: make([]*jw.Workflow, 0),
}
}
func (ms *memoryStorage) State() (*storage.State, error) {
state := new(storage.State)
ms.sm.Lock()
defer ms.sm.Unlock()
for _, job := range ms.jobs {
switch job.Status {
case jw.StatusTodo:
state.Jobs.Todo += 1
case jw.StatusPending:
state.Jobs.Pending += 1
case jw.StatusRunning:
state.Jobs.Running += 1
case jw.StatusSucceeded:
state.Jobs.Succeeded += 1
case jw.StatusFailed:
state.Jobs.Failed += 1
}
}
state.Jobs.Total = len(ms.jobs)
for _, wf := range ms.workflows {
switch wf.Status {
case jw.StatusRunning:
state.Workflows.Running += 1
case jw.StatusSucceeded:
state.Workflows.Succeeded += 1
case jw.StatusFailed:
state.Workflows.Failed += 1
}
}
state.Workflows.Total = len(ms.workflows)
return state, nil
}
func (ms *memoryStorage) Close() error {
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/