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.

69 lines
1.5 KiB

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