Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
349a584ad0
  1. 28
      internal/model/next.go
  2. 10
      internal/storage/memory/next.go

28
internal/model/next.go

@ -12,8 +12,32 @@ import (
)
func selectNextJob(jr jw.JobsRunning, jtr jw.JobsToRun) (*jw.Job, error) {
// AFINIR
return nil, nil
for {
job, err := jtr.Next()
if job == nil || err != nil {
return nil, err
}
if jr != nil && len(jr) > 0 {
if job.Exclusivity == jw.ExclusivityNamespace {
return nil, nil
}
if job.Exclusivity == jw.ExclusivityItself {
if _, ok := jr[job.Type]; ok {
continue
}
}
if job.MaxOccurences > 0 {
if n, ok := jr[job.Type]; ok && n >= job.MaxOccurences {
continue
}
}
}
return job, nil
}
}
func (m *Model) NextJob(namespace string) (*jw.Job, error) {

10
internal/storage/memory/next.go

@ -31,15 +31,13 @@ func (jtr *jobsToRun) Next() (*jw.Job, error) {
return nil, nil
}
func (m *memory) jobsRunning() jw.JobsRunning {
func (m *memory) jobsRunning(namespace string) jw.JobsRunning {
jr := make(jw.JobsRunning)
for _, job := range m.jobs {
if job.Status != jw.StatusRunning {
continue
if job.Namespace == namespace && job.Status == jw.StatusRunning {
jr[job.Type] += 1
}
jr[job.Namespace+job.Type] += 1
}
return jr
@ -68,7 +66,7 @@ func (m *memory) NextJob(namespace string, fn jw.SelectNextJob) (*jw.Job, error)
jobs: jobs,
}
job, err := fn(m.jobsRunning(), jtr)
job, err := fn(m.jobsRunning(namespace), jtr)
if job == nil || err != nil {
return nil, err
}

Loading…
Cancel
Save