Browse Source

En cours de développement

master
losyme 3 months ago
parent
commit
5d2d1daa8d
  1. 2
      go.mod
  2. 4
      go.sum
  3. 4
      internal/model/next.go
  4. 1
      internal/model/validate.go
  5. 22
      internal/storage/memory/next.go

2
go.mod

@ -3,7 +3,7 @@ module forge.chapril.org/dune/dune
go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20211107140032-0ca6aa531d22
forge.chapril.org/dune/jw v0.0.0-20211107164502-530cf6d1f075
forge.chapril.org/losyme/application v0.0.0-20211029102910-b7db6effc015
forge.chapril.org/losyme/cmdline v0.0.0-20211029192907-e6f74788c44f
forge.chapril.org/losyme/config v0.0.0-20211025142334-51a8a7a73a4f

4
go.sum

@ -1,5 +1,5 @@
forge.chapril.org/dune/jw v0.0.0-20211107140032-0ca6aa531d22 h1:2DYjk+F3rchimX2uBwWAj7fG4jIf2wReCkh56pGKUuw=
forge.chapril.org/dune/jw v0.0.0-20211107140032-0ca6aa531d22/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
forge.chapril.org/dune/jw v0.0.0-20211107164502-530cf6d1f075 h1:H36G3/qCMW+S8MYfOoywy6g4v3xoiWa6EEQBElMIH0s=
forge.chapril.org/dune/jw v0.0.0-20211107164502-530cf6d1f075/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
forge.chapril.org/losyme/application v0.0.0-20211029102910-b7db6effc015 h1:mZQ2kC2ucXI0lNRVyIOVEz3zu0ChOQ9wTPG0W69fI1Y=
forge.chapril.org/losyme/application v0.0.0-20211029102910-b7db6effc015/go.mod h1:olQo5n5tnBRHq0wcc0lNbymvsXdTuYaCjNfd2d/+01w=
forge.chapril.org/losyme/buffer v0.0.0-20211003203540-771701f5a518 h1:B7wu0DWUwpt0Mw/VTuWQZikhV/VD6kc2iJWbIY+jgEM=

4
internal/model/next.go

@ -17,7 +17,7 @@ func selectNextJob(jr jw.JobsRunning, jtr jw.JobsToRun) (*jw.Job, error) {
}
func (m *Model) NextJob(namespace string) (*jw.Job, error) {
job, err := m.Storage.NextJob(selectNextJob)
job, err := m.Storage.NextJob(namespace, selectNextJob)
if err != nil {
m.Logger.Warning( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Cannot retrieve the next job to run",
@ -33,7 +33,6 @@ func (m *Model) NextJob(namespace string) (*jw.Job, error) {
job.Session += 1
job.Result = nil
job.Weight += 1
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Next job",
@ -41,7 +40,6 @@ func (m *Model) NextJob(namespace string) (*jw.Job, error) {
job.Fields(),
"attempt", job.Attempt,
"session", job.Session,
"weight", job.Weight,
)...,
)

1
internal/model/validate.go

@ -89,7 +89,6 @@ func (m *Model) validateJob(job *jw.Job) error {
job.Session = 0
job.Result = nil
job.FinishedAt = nil
job.Weight = 0
job.TimeReference = job.CreatedAt
return nil

22
internal/storage/memory/next.go

@ -14,14 +14,15 @@ import (
)
type jobsToRun struct { // AFINIR: sync.Pool ?
jobs []*jw.Job
now time.Time
namespace string
jobs []*jw.Job
}
func (jtr *jobsToRun) Next() (*jw.Job, error) {
now := time.Now()
for i, job := range jtr.jobs {
if (job.Status == jw.StatusTodo || job.Status == jw.StatusPending) && job.RunAfter.Before(now) {
if job.Namespace == jtr.namespace &&
(job.Status == jw.StatusTodo || job.Status == jw.StatusPending) && job.RunAfter.Before(jtr.now) {
jtr.jobs = jtr.jobs[i+1:]
return job, nil
}
@ -44,7 +45,7 @@ func (m *memory) jobsRunning() jw.JobsRunning {
return jr
}
func (m *memory) NextJob(fn jw.SelectNextJob) (*jw.Job, error) {
func (m *memory) NextJob(namespace string, fn jw.SelectNextJob) (*jw.Job, error) {
m.sm.Lock()
defer m.sm.Unlock()
@ -57,11 +58,17 @@ func (m *memory) NextJob(fn jw.SelectNextJob) (*jw.Job, error) {
ji := jobs[i]
jj := jobs[j]
return ji.Priority > jj.Priority || ji.Weight < jj.Weight || ji.TimeReference.Before(jj.TimeReference)
return ji.Priority > jj.Priority || ji.Session < jj.Session || ji.TimeReference.Before(jj.TimeReference)
},
)
job, err := fn(m.jobsRunning(), &jobsToRun{jobs})
jtr := &jobsToRun{
now: time.Now(),
namespace: namespace,
jobs: jobs,
}
job, err := fn(m.jobsRunning(), jtr)
if job == nil || err != nil {
return nil, err
}
@ -71,7 +78,6 @@ func (m *memory) NextJob(fn jw.SelectNextJob) (*jw.Job, error) {
*clone = *job
job.Status = jw.StatusRunning
job.Weight++
return clone, nil
}

Loading…
Cancel
Save