Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
15362585a3
  1. 2
      go.mod
  2. 4
      go.sum
  3. 4
      internal/model/jobs.go
  4. 53
      internal/model/next.go
  5. 4
      internal/storage/memory/jobs.go
  6. 61
      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-20211106184939-3b001b238eb2
forge.chapril.org/dune/jw v0.0.0-20211107140032-0ca6aa531d22
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-20211106184939-3b001b238eb2 h1:cz6IwVTioi4+DsWTYM2T0/RBFPFLggpWmF0HLl0ooxs=
forge.chapril.org/dune/jw v0.0.0-20211106184939-3b001b238eb2/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
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/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/jobs.go

@ -60,10 +60,6 @@ func (m *Model) CreateJob(job *jw.Job) (*jw.Job, error) {
return nil, nil
}
func (m *Model) NextJob(namespace string) (*jw.Job, error) {
return nil, nil
}
func (m *Model) UpdateJob(job *jw.Job) (*jw.Job, error) {
return nil, nil
}

53
internal/model/next.go

@ -0,0 +1,53 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package model
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
)
func selectNextJob(jr jw.JobsRunning, jtr jw.JobsToRun) (*jw.Job, error) {
// AFINIR
return nil, nil
}
func (m *Model) NextJob(namespace string) (*jw.Job, error) {
job, err := m.Storage.NextJob(selectNextJob)
if err != nil {
m.Logger.Warning( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Cannot retrieve the next job to run",
"reason", err,
)
return nil, errors.WithMessage(err, "cannot retrieve the next job to run") /////////////////////////////////////
}
if job == nil {
return nil, nil
}
job.Session += 1
job.Result = nil
job.Weight += 1
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Next job",
append(
job.Fields(),
"attempt", job.Attempt,
"session", job.Session,
"weight", job.Weight,
)...,
)
return job, nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

4
internal/storage/memory/jobs.go

@ -58,10 +58,6 @@ func (m *memory) InsertJob(job *jw.Job) (bool, error) {
return m.insertJob(job)
}
func (m *memory) NextJob(namespace string) (*jw.Job, error) {
return nil, nil
}
func (m *memory) updateJob(job *jw.Job) error {
if i, j := m.findJob(job.ID); j != nil {
m.jobs[i] = job

61
internal/storage/memory/next.go

@ -0,0 +1,61 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package memory
import "forge.chapril.org/dune/jw"
type jobsToRun struct { // AFINIR: sync.Pool ?
jobs []*jw.Job
}
func (jtr *jobsToRun) Next() (*jw.Job, error) {
for i, job := range jtr.jobs {
if job.Status == jw.StatusTodo {
jtr.jobs = jtr.jobs[i+1:]
return job, nil
}
}
return nil, nil
}
func (m *memory) jobsRunning() jw.JobsRunning {
jr := make(jw.JobsRunning)
for _, job := range m.jobs {
if job.Status != jw.StatusRunning {
continue
}
jr[job.Namespace+job.Type] += 1
}
return jr
}
func (m *memory) NextJob(fn jw.SelectNextJob) (*jw.Job, error) {
m.sm.Lock()
defer m.sm.Unlock()
job, err := fn(m.jobsRunning(), &jobsToRun{jobs: m.jobs})
if job == nil || err != nil {
return nil, err
}
// Sufffisant ?
clone := new(jw.Job)
*clone = *job
job.Status = jw.StatusRunning
job.Weight++
return clone, nil
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save