Browse Source

En cours de développement

master
losyme 5 months ago
parent
commit
36f334dca3
  1. 4
      go.mod
  2. 8
      go.sum
  3. 7
      internal/api/api.go
  4. 7
      internal/components/components.go
  5. 7
      internal/model/model.go
  6. 3
      internal/model/next.go
  7. 9
      internal/model/storage.go
  8. 5
      internal/storage/memory/jobs.go
  9. 7
      internal/storage/memory/memory.go
  10. 7
      internal/storage/memory/next.go
  11. 5
      internal/storage/memory/workflows.go
  12. 4
      internal/storage/storage.go

4
go.mod

@ -3,8 +3,8 @@ module forge.chapril.org/dune/dune
go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20211205143034-b316149dd167
forge.chapril.org/dune/sdk v0.0.0-20211211201548-2baf47ee2007
forge.chapril.org/dune/jw v0.0.0-20211212110653-0fbfac5be8fc
forge.chapril.org/dune/sdk v0.0.0-20211212113207-d73185ea4564
forge.chapril.org/losyme/application v0.0.0-20211029102910-b7db6effc015
forge.chapril.org/losyme/cmdline v0.0.0-20211205162853-bbfce16ddfa4
forge.chapril.org/losyme/config v0.0.0-20211211183753-155ce34386be

8
go.sum

@ -1,7 +1,7 @@
forge.chapril.org/dune/jw v0.0.0-20211205143034-b316149dd167 h1:IslU++qhiIM+BxkfeduMfjEu6TgwaRrqSYlNcucLzKE=
forge.chapril.org/dune/jw v0.0.0-20211205143034-b316149dd167/go.mod h1:LEDlIDkGkdvYAzSdZeucZDkbhkf0K5WUV7rTK8ILsc4=
forge.chapril.org/dune/sdk v0.0.0-20211211201548-2baf47ee2007 h1:ymqkDMH3gs1xVi8haF48iPFxOIpxn2lqs+YvgtVTJvk=
forge.chapril.org/dune/sdk v0.0.0-20211211201548-2baf47ee2007/go.mod h1:EfaacCgNIHO4NpZL4ZzetuZjTBjO48+ldbJgQNf2MuI=
forge.chapril.org/dune/jw v0.0.0-20211212110653-0fbfac5be8fc h1:GkiPEqkns9+lGzpC5Li3IY9YifnvpqCSozOfW/nx4E4=
forge.chapril.org/dune/jw v0.0.0-20211212110653-0fbfac5be8fc/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
forge.chapril.org/dune/sdk v0.0.0-20211212113207-d73185ea4564 h1:v4/Skjx/OVuLyIi7+A+lqqnK34eJlpItcHL8NYfLyKg=
forge.chapril.org/dune/sdk v0.0.0-20211212113207-d73185ea4564/go.mod h1:LJAlcKIKZ4GMWbsXSy9jaMO/TNC8OY8EQ9Gq3dVQfvE=
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/breaker v0.0.0-20211211181953-36cc377d4b8d/go.mod h1:1vBH8Q+vML8EBZj1Pvcpzxx+eEBK+f24QzcXT5Bo+MY=

7
internal/api/api.go

@ -9,8 +9,7 @@ package api
import (
"net/http"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/kong/context"
"forge.chapril.org/losyme/kong/middleware"
"forge.chapril.org/losyme/kong/middleware/json"
@ -23,8 +22,8 @@ import (
type API struct {
logger *logger.Component
model runner.Model
storage jw.Storage
model sdk.Model
storage sdk.Storage
}
func Build(cs *components.Components) (*API, error) {

7
internal/components/components.go

@ -7,15 +7,14 @@
package components
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/minikit/pkg/components"
)
type Components struct {
*components.Components
Model runner.Model
Storage jw.Storage
Model sdk.Model
Storage sdk.Storage
}
/*

7
internal/model/model.go

@ -7,8 +7,7 @@
package model
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/logger"
"forge.chapril.org/losyme/uuid"
@ -20,10 +19,10 @@ const ErrValidation = errors.Sentinel("validation error")
type model struct {
logger *logger.Component
storage jw.Storage
storage sdk.Storage
}
func Build(cs *components.Components) (runner.Model, error) {
func Build(cs *components.Components) (sdk.Model, error) {
logger, err := cs.Logger.Clone(uuid.New(), "model")
if err != nil {
return nil, err

3
internal/model/next.go

@ -8,10 +8,11 @@ package model
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/errors"
)
func selectNextJob(jr jw.JobsRunning, jtr jw.JobsToRun) (*jw.Job, error) {
func selectNextJob(jr sdk.JobsRunning, jtr sdk.JobsToRun) (*jw.Job, error) {
for {
job, err := jtr.Next()
if job == nil || err != nil {

9
internal/model/storage.go

@ -11,6 +11,7 @@ import (
"fmt"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
)
func (m *model) logJob(job *jw.Job) {
@ -38,7 +39,7 @@ func (m *model) logJob(job *jw.Job) {
func (m *model) storageInsertJob(job *jw.Job) (bool, error) {
done, err := m.storage.InsertJob(job)
if err != nil {
if errors.Is(err, jw.ErrStorage) {
if errors.Is(err, sdk.ErrStorage) {
return false, err
}
@ -58,7 +59,7 @@ func (m *model) storageInsertJob(job *jw.Job) (bool, error) {
func (m *model) storageUpdateJob(job *jw.Job) error {
if err := m.storage.UpdateJob(job); err != nil {
if errors.Is(err, jw.ErrStorage) {
if errors.Is(err, sdk.ErrStorage) {
return err
}
@ -88,7 +89,7 @@ func (m *model) logWorkflow(wf *jw.Workflow) {
func (m *model) storageInsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
// Cette insertion doit être faite dans une transaction.
if err := m.storage.InsertWorkflow(wf, job); err != nil {
if errors.Is(err, jw.ErrStorage) {
if errors.Is(err, sdk.ErrStorage) {
return err
}
@ -105,7 +106,7 @@ func (m *model) storageInsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
func (m *model) storageUpdateWorkflow(wf *jw.Workflow, job, nextJob *jw.Job) error {
// Cette mise à jour doit être faite dans une transaction.
if err := m.storage.UpdateWorkflow(wf, job, nextJob); err != nil {
if errors.Is(err, jw.ErrStorage) {
if errors.Is(err, sdk.ErrStorage) {
return err
}

5
internal/storage/memory/jobs.go

@ -10,6 +10,7 @@ import (
"time"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/errors"
)
@ -30,7 +31,7 @@ func (m *memory) ValidateJob(_ *jw.Job) error {
func (m *memory) insertJob(job *jw.Job) (bool, error) {
if _, j := m.findJob(job.ID); j != nil {
return false, errors.Wrap( /////////////////////////////////////////////////////////////////////////////////////
jw.ErrStorage,
sdk.ErrStorage,
errors.New("this job identifier already exists", "id", job.ID),
)
}
@ -65,7 +66,7 @@ func (m *memory) updateJob(job *jw.Job) error {
}
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////////////
jw.ErrStorage,
sdk.ErrStorage,
errors.New("this job does not exist", "job", job.ID),
)
}

7
internal/storage/memory/memory.go

@ -10,6 +10,7 @@ import (
"sync"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
)
type memory struct {
@ -18,15 +19,15 @@ type memory struct {
workflows []*jw.Workflow
}
func New() jw.Storage {
func New() sdk.Storage {
return &memory{
jobs: make([]*jw.Job, 0),
workflows: make([]*jw.Workflow, 0),
}
}
func (m *memory) Dashboard() (*jw.Dashboard, error) {
stats := new(jw.Dashboard)
func (m *memory) Dashboard() (*sdk.Dashboard, error) {
stats := new(sdk.Dashboard)
m.sm.Lock()
defer m.sm.Unlock()

7
internal/storage/memory/next.go

@ -11,6 +11,7 @@ import (
"time"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
)
type jobsToRun struct { // AFINIR: sync.Pool ?
@ -31,8 +32,8 @@ func (jtr *jobsToRun) Next() (*jw.Job, error) {
return nil, nil
}
func (m *memory) jobsRunning(namespace string) jw.JobsRunning {
jr := make(jw.JobsRunning)
func (m *memory) jobsRunning(namespace string) sdk.JobsRunning {
jr := make(sdk.JobsRunning)
for _, job := range m.jobs {
if job.Namespace == namespace && job.Status == jw.StatusRunning {
@ -43,7 +44,7 @@ func (m *memory) jobsRunning(namespace string) jw.JobsRunning {
return jr
}
func (m *memory) NextJob(namespace string, fn jw.SelectNextJob) (*jw.Job, error) {
func (m *memory) NextJob(namespace string, fn sdk.SelectNextJob) (*jw.Job, error) {
m.sm.Lock()
defer m.sm.Unlock()

5
internal/storage/memory/workflows.go

@ -8,6 +8,7 @@ package memory
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/errors"
)
@ -31,7 +32,7 @@ func (m *memory) InsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
if _, w := m.findWorkflow(wf.ID); w != nil {
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////////
jw.ErrStorage,
sdk.ErrStorage,
errors.New("this workflow identifier already exists", "id", wf.ID),
)
}
@ -72,7 +73,7 @@ func (m *memory) UpdateWorkflow(wf *jw.Workflow, job, nextJob *jw.Job) error {
i, w := m.findWorkflow(wf.ID)
if w == nil {
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////
jw.ErrStorage,
sdk.ErrStorage,
errors.New("this workflow does not exist", "wf", wf.ID),
)
}

4
internal/storage/storage.go

@ -7,14 +7,14 @@
package storage
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/dune/internal/components"
"forge.chapril.org/dune/dune/internal/storage/memory"
)
func Build(cs *components.Components) (jw.Storage, error) {
func Build(cs *components.Components) (sdk.Storage, error) {
impl, err := cs.Config.GetString("storage")
if err != nil {
return nil, err

Loading…
Cancel
Save