Browse Source

En cours de développement

master
losyme 5 months ago
parent
commit
129aa2bc30
  1. 46
      internal/api/api.go
  2. 2
      internal/api/jobs.go
  3. 39
      internal/application/api.go
  4. 24
      internal/application/application.go
  5. 26
      internal/application/demo.go
  6. 43
      internal/application/factory.go
  7. 35
      internal/application/model.go
  8. 9
      internal/components/components.go
  9. 11
      internal/demo/demo.go
  10. 30
      internal/model/jobs.go
  11. 24
      internal/model/model.go
  12. 8
      internal/model/next.go
  13. 32
      internal/model/storage.go
  14. 8
      internal/model/validate.go
  15. 20
      internal/model/workflows.go
  16. 15
      internal/storage/storage.go

46
internal/api/api.go

@ -10,41 +10,57 @@ import (
"net/http"
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/losyme/kong/context"
"forge.chapril.org/losyme/kong/middleware"
"forge.chapril.org/losyme/kong/middleware/json"
"forge.chapril.org/losyme/kong/router"
"forge.chapril.org/losyme/logger"
"forge.chapril.org/losyme/uuid"
"forge.chapril.org/dune/dune/internal/model"
"forge.chapril.org/dune/dune/internal/components"
)
type API struct {
Router *router.Router
Model *model.Model
Storage jw.Storage
Logger *logger.Component
logger *logger.Component
model runner.Model
storage jw.Storage
}
func (api *API) Build() {
api.Router.MethodNotAllowed = json.MethodNotAllowed(api.Logger)
api.Router.NotFound = json.NotFound(api.Logger)
api.Router.OnRecover = json.OnRecover(api.Logger)
func Build(cs *components.Components) (*API, error) {
logger, err := cs.Logger.Clone(uuid.New(), "api")
if err != nil {
return nil, err
}
csr := cs.Router
csr.MethodNotAllowed = json.MethodNotAllowed(logger)
csr.NotFound = json.NotFound(logger)
csr.OnRecover = json.OnRecover(logger)
api.Router.Use(
csr.Use(
middleware.RequestID(),
middleware.Logger(api.Logger),
json.OnError(api.Logger),
middleware.Logger(logger),
json.OnError(logger),
)
api.Router.Group("/api", func(g *router.Group) { // api.............................................................
api := &API{
logger: logger,
model: cs.Model,
storage: cs.Storage,
}
csr.Group("/api", func(g *router.Group) { // api....................................................................
g.Get("/status", api.status)
g.Get("/dashboard", api.dashboard)
g.New("/jobs", func(g2 *router.Group) { // api/jobs..............................................................
g.New("/jobs", func(g2 *router.Group) { // api/jobs.............................................................
g2.Post("", api.createJob)
})
})
return api, nil
}
func (api *API) status(c *context.Context) error {
@ -52,7 +68,7 @@ func (api *API) status(c *context.Context) error {
}
func (api *API) dashboard(c *context.Context) error {
stats, err := api.Storage.Dashboard()
stats, err := api.storage.Dashboard()
if err != nil {
return err
}

2
internal/api/jobs.go

@ -29,7 +29,7 @@ func (api *API) createJob(c *context.Context) error {
job.ID = c.RequestID()
}
job, err := api.Model.CreateJob(job)
job, err := api.model.CreateJob(job)
if err != nil {
status := http.StatusInternalServerError

39
internal/application/api.go

@ -1,39 +0,0 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"forge.chapril.org/losyme/uuid"
"forge.chapril.org/dune/dune/internal/api"
)
func (app *Application) API() error {
cs := app.components
logger, err := cs.Logger.Clone(uuid.New(), "api")
if err != nil {
return err
}
c := &api.API{
Router: cs.Router,
Model: cs.Model,
Storage: cs.Storage,
Logger: logger,
}
c.Build()
app.components.API = c
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

24
internal/application/application.go

@ -13,7 +13,9 @@ import (
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/minikit"
"forge.chapril.org/dune/dune/internal/api"
"forge.chapril.org/dune/dune/internal/components"
"forge.chapril.org/dune/dune/internal/demo"
)
const _serverShutdownTimeout = 10 * time.Second
@ -22,6 +24,8 @@ type Application struct {
minikit *minikit.Kit
components *components.Components
cmdLine *cmdLine
api *api.API
demo *demo.Demo
}
func New(name, version, builtAt string, args []string) *Application {
@ -68,8 +72,8 @@ func (app *Application) Run() error {
}
}
if err := app.storage(); err != nil {
return errors.WithMessage(err, "storage") //////////////////////////////////////////////////////////////
if err := app.build("storage"); err != nil {
return err
}
defer func() {
@ -78,22 +82,22 @@ func (app *Application) Run() error {
}
}()
if err := app.model(); err != nil {
return errors.WithMessage(err, "model") ////////////////////////////////////////////////////////////////
if err := app.build("model"); err != nil {
return err
}
if err := app.API(); err != nil {
return errors.WithMessage(err, "API") //////////////////////////////////////////////////////////////////
if err := app.build("api"); err != nil {
return err
}
if app.cmdLine.demo {
if err := app.demo(); err != nil {
return errors.WithMessage(err, "demo") /////////////////////////////////////////////////////////////
if err := app.build("demo"); err != nil {
return err
}
cs.Demo.Start()
app.demo.Start()
defer cs.Demo.Stop()
defer app.demo.Stop()
}
app.components.Scheduler.Start()

26
internal/application/demo.go

@ -1,26 +0,0 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import "forge.chapril.org/dune/dune/internal/demo"
func (app *Application) demo() error {
cs := app.components
c, err := demo.New(cs.Logger.Component, cs.Model)
if err != nil {
return err
}
cs.Demo = c
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

43
internal/application/factory.go

@ -0,0 +1,43 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/dune/internal/api"
"forge.chapril.org/dune/dune/internal/demo"
"forge.chapril.org/dune/dune/internal/model"
"forge.chapril.org/dune/dune/internal/storage"
)
func (app *Application) build(component string) (err error) {
cs := app.components
switch component {
case "api":
app.api, err = api.Build(cs)
case "demo":
app.demo, err = demo.Build(cs)
case "model":
cs.Model, err = model.Build(cs)
case "storage":
cs.Storage, err = storage.Build(cs)
default:
return errors.New("this component doesn't exist", "name", component) ///////////////////////////////////////////
}
if err != nil {
err = errors.WithMessage(err, component) ///////////////////////////////////////////////////////////////////////
}
return
}
/*
######################################################################################################## @(°_°)@ #######
*/

35
internal/application/model.go

@ -1,35 +0,0 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"forge.chapril.org/losyme/uuid"
"forge.chapril.org/dune/dune/internal/model"
)
func (app *Application) model() error {
cs := app.components
logger, err := cs.Logger.Clone(uuid.New(), "model")
if err != nil {
return err
}
c := &model.Model{
Storage: cs.Storage,
Logger: logger,
}
cs.Model = c
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/

9
internal/components/components.go

@ -8,18 +8,13 @@ package components
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/losyme/minikit/pkg/components"
"forge.chapril.org/dune/dune/internal/api"
"forge.chapril.org/dune/dune/internal/demo"
"forge.chapril.org/dune/dune/internal/model"
)
type Components struct {
*components.Components
API *api.API
Demo *demo.Demo
Model *model.Model
Model runner.Model
Storage jw.Storage
}

11
internal/demo/demo.go

@ -9,8 +9,9 @@ package demo
import (
"forge.chapril.org/dune/sdk/runner"
"forge.chapril.org/dune/sdk/workers"
"forge.chapril.org/losyme/logger"
"github.com/Showmax/go-fqdn"
"forge.chapril.org/dune/dune/internal/components"
)
const (
@ -22,21 +23,21 @@ type Demo struct {
*workers.Workers
}
func New(logger *logger.Component, model runner.Model) (*Demo, error) {
func Build(cs *components.Components) (*Demo, error) {
fqdn, err := fqdn.FqdnHostname()
if err != nil {
logger.Warning("Unable to retrieve the FQDN", "reason", err) //:::::::::::::::::::::::::::::::::::::::::::::::::
cs.Logger.Warning("Unable to retrieve the FQDN", "reason", err) //::::::::::::::::::::::::::::::::::::::::::::::
fqdn = "?"
}
r := runner.New(_namespace, model)
r := runner.New(_namespace, cs.Model)
cfg := &workers.Config{
PoolSize: _workerPoolSize,
Host: fqdn,
Runner: r,
Logger: newWorkersLogger(logger),
Logger: newWorkersLogger(cs.Logger.Component),
}
workers, err := workers.New(cfg)

30
internal/model/jobs.go

@ -13,7 +13,7 @@ import (
"forge.chapril.org/losyme/errors"
)
func (m *Model) createJob(job *jw.Job) (bool, error) {
func (m *model) createJob(job *jw.Job) (bool, error) {
if err := m.validateJob(job); err != nil {
return false, errors.Wrap( /////////////////////////////////////////////////////////////////////////////////////
ErrValidation,
@ -29,10 +29,10 @@ func (m *Model) createJob(job *jw.Job) (bool, error) {
return done, nil
}
func (m *Model) CreateJob(job *jw.Job) (*jw.Job, error) {
func (m *model) CreateJob(job *jw.Job) (*jw.Job, error) {
done, err := m.createJob(job)
if err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Unable to create this job",
append(
job.Fields(),
@ -50,11 +50,11 @@ func (m *Model) CreateJob(job *jw.Job) (*jw.Job, error) {
return nil, nil
}
func (m *Model) updateJob(job *jw.Job) error {
func (m *model) updateJob(job *jw.Job) error {
if job.Workflow == nil || job.Status == jw.StatusPending {
err := m.storageUpdateJob(job)
if err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Unable to update this job",
append(
job.Fields(),
@ -66,9 +66,9 @@ func (m *Model) updateJob(job *jw.Job) error {
return err
}
wf, err := m.Storage.Workflow(*job.Workflow, true)
wf, err := m.storage.Workflow(*job.Workflow, true)
if err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Cannot retrieve the workflow of this job",
append(
job.Fields(),
@ -80,7 +80,7 @@ func (m *Model) updateJob(job *jw.Job) error {
}
if err := m.updateWorkflow(wf, job); err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Unable to update this workflow",
append(
wf.Fields(),
@ -94,14 +94,14 @@ func (m *Model) updateJob(job *jw.Job) error {
return nil
}
func (m *Model) UpdateJob(job *jw.Job) (*jw.Job, error) {
func (m *model) UpdateJob(job *jw.Job) (*jw.Job, error) {
if job.Result == nil {
job.Succeeded()
}
jr := job.Result
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Job result",
"id", job.ID,
"status", jr.Status,
@ -144,17 +144,17 @@ func (m *Model) UpdateJob(job *jw.Job) (*jw.Job, error) {
return job, nil
}
func (m *Model) NotifyJob(id string, data interface{}) error {
func (m *model) NotifyJob(id string, data interface{}) error {
// AFINIR
return nil
}
func (m *Model) SetJobPriority(id string, priority jw.Priority) error {
return m.Storage.SetJobPriority(id, priority)
func (m *model) SetJobPriority(id string, priority jw.Priority) error {
return m.storage.SetJobPriority(id, priority)
}
func (m *Model) SetJobRunAfter(id string, duration time.Duration) error {
return m.Storage.SetJobRunAfter(id, duration)
func (m *model) SetJobRunAfter(id string, duration time.Duration) error {
return m.storage.SetJobRunAfter(id, duration)
}
/*

24
internal/model/model.go

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

8
internal/model/next.go

@ -40,10 +40,10 @@ 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(namespace, selectNextJob)
func (m *model) NextJob(namespace string) (*jw.Job, error) {
job, err := m.storage.NextJob(namespace, selectNextJob)
if err != nil {
m.Logger.Warning( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Warning( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Cannot retrieve the next job to run",
"reason", err,
)
@ -58,7 +58,7 @@ func (m *Model) NextJob(namespace string) (*jw.Job, error) {
job.Session += 1
job.Result = nil
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Next job",
append(
job.Fields(),

32
internal/model/storage.go

@ -13,12 +13,12 @@ import (
"forge.chapril.org/dune/jw"
)
func (m *Model) logJob(job *jw.Job) {
func (m *model) logJob(job *jw.Job) {
switch job.Status {
case jw.StatusTodo:
m.Logger.Info("New job", job.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info("New job", job.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
case jw.StatusPending:
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Job to continue",
"id", job.ID,
"run_after", job.RunAfter.String(),
@ -26,7 +26,7 @@ func (m *Model) logJob(job *jw.Job) {
"session", job.Session,
)
default:
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Job finished",
"id", job.ID,
"status", job.Status,
@ -35,8 +35,8 @@ func (m *Model) logJob(job *jw.Job) {
}
}
func (m *Model) storageInsertJob(job *jw.Job) (bool, error) {
done, err := m.Storage.InsertJob(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) {
return false, err
@ -47,7 +47,7 @@ func (m *Model) storageInsertJob(job *jw.Job) (bool, error) {
}
if !done {
m.Logger.Notice("A job with the same category already exists", job.Fields()...) //::::::::::::::::::::::::::::::
m.logger.Notice("A job with the same category already exists", job.Fields()...) //::::::::::::::::::::::::::::::
return false, nil
}
@ -56,8 +56,8 @@ func (m *Model) storageInsertJob(job *jw.Job) (bool, error) {
return true, nil
}
func (m *Model) storageUpdateJob(job *jw.Job) error {
if err := m.Storage.UpdateJob(job); err != nil {
func (m *model) storageUpdateJob(job *jw.Job) error {
if err := m.storage.UpdateJob(job); err != nil {
if errors.Is(err, jw.ErrStorage) {
return err
}
@ -71,12 +71,12 @@ func (m *Model) storageUpdateJob(job *jw.Job) error {
return nil
}
func (m *Model) logWorkflow(wf *jw.Workflow) {
func (m *model) logWorkflow(wf *jw.Workflow) {
switch wf.Status {
case jw.StatusRunning:
m.Logger.Info("New workflow [begin]", wf.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info("New workflow [begin]", wf.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::
default:
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Workflow finished",
"id", wf.ID,
"status", wf.Status,
@ -85,9 +85,9 @@ func (m *Model) logWorkflow(wf *jw.Workflow) {
}
}
func (m *Model) storageInsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
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 err := m.storage.InsertWorkflow(wf, job); err != nil {
if errors.Is(err, jw.ErrStorage) {
return err
}
@ -102,9 +102,9 @@ func (m *Model) storageInsertWorkflow(wf *jw.Workflow, job *jw.Job) error {
return nil
}
func (m *Model) storageUpdateWorkflow(wf *jw.Workflow, job, nextJob *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 err := m.storage.UpdateWorkflow(wf, job, nextJob); err != nil {
if errors.Is(err, jw.ErrStorage) {
return err
}

8
internal/model/validate.go

@ -35,8 +35,8 @@ func validatePriority(p *jw.Priority) {
}
}
func (m *Model) validateJob(job *jw.Job) error {
if err := m.Storage.ValidateJob(job); err != nil {
func (m *model) validateJob(job *jw.Job) error {
if err := m.storage.ValidateJob(job); err != nil {
return err
}
@ -162,8 +162,8 @@ func validateStep(wf *jw.Workflow, step *jw.Step) error {
return validateNext(wf, step.Next)
}
func (m *Model) validateWorkflow(wf *jw.Workflow) error {
if err := m.Storage.ValidateWorkflow(wf); err != nil {
func (m *model) validateWorkflow(wf *jw.Workflow) error {
if err := m.storage.ValidateWorkflow(wf); err != nil {
return err
}

20
internal/model/workflows.go

@ -15,7 +15,7 @@ import (
"forge.chapril.org/losyme/uuid"
)
func (m *Model) stepToJob(wf *jw.Workflow, name string) (*jw.Job, error) {
func (m *model) stepToJob(wf *jw.Workflow, name string) (*jw.Job, error) {
step, ok := wf.AllSteps[name]
if !ok {
return nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////////
@ -43,7 +43,7 @@ func (m *Model) stepToJob(wf *jw.Workflow, name string) (*jw.Job, error) {
return job, nil
}
func (m *Model) createWorkflow(wf *jw.Workflow) error {
func (m *model) createWorkflow(wf *jw.Workflow) error {
if err := m.validateWorkflow(wf); err != nil {
return errors.Wrap( ////////////////////////////////////////////////////////////////////////////////////////////
ErrValidation,
@ -68,9 +68,9 @@ func (m *Model) createWorkflow(wf *jw.Workflow) error {
return nil
}
func (m *Model) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
func (m *model) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
if err := m.createWorkflow(wf); err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Unable to create this workflow",
append(
wf.Fields(),
@ -84,7 +84,7 @@ func (m *Model) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
return wf, nil
}
func (m *Model) nextStepAdvanced(step string, value interface{}) (string, map[string]interface{}, error) {
func (m *model) nextStepAdvanced(step string, value interface{}) (string, map[string]interface{}, error) {
switch next := value.(type) {
case nil:
return "", nil, nil
@ -136,7 +136,7 @@ func (m *Model) nextStepAdvanced(step string, value interface{}) (string, map[st
}
}
func (m *Model) nextStep(wf *jw.Workflow, job *jw.Job) (string, map[string]interface{}, error) {
func (m *model) nextStep(wf *jw.Workflow, job *jw.Job) (string, map[string]interface{}, error) {
jr := job.Result
if jr.NextStep != "" {
@ -174,7 +174,7 @@ func (m *Model) nextStep(wf *jw.Workflow, job *jw.Job) (string, map[string]inter
)
}
func (m *Model) nextJob(wf *jw.Workflow, job *jw.Job, stepName string, data map[string]interface{}) (*jw.Job, error) {
func (m *model) nextJob(wf *jw.Workflow, job *jw.Job, stepName string, data map[string]interface{}) (*jw.Job, error) {
nextJob, err := m.stepToJob(wf, stepName)
if err != nil {
return nil, err
@ -186,7 +186,7 @@ func (m *Model) nextJob(wf *jw.Workflow, job *jw.Job, stepName string, data map[
return nextJob, nil
}
func (m *Model) updateWorkflow(wf *jw.Workflow, job *jw.Job) error {
func (m *model) updateWorkflow(wf *jw.Workflow, job *jw.Job) error {
stepName, data, err := m.nextStep(wf, job)
if err != nil {
return err
@ -208,8 +208,8 @@ func (m *Model) updateWorkflow(wf *jw.Workflow, job *jw.Job) error {
return m.storageUpdateWorkflow(nil, job, nextJob)
}
func (m *Model) SetWorkflowPriority(id string, priority jw.Priority) error {
return m.Storage.SetWorkflowPriority(id, priority)
func (m *model) SetWorkflowPriority(id string, priority jw.Priority) error {
return m.storage.SetWorkflowPriority(id, priority)
}
/*

15
internal/application/storage.go → internal/storage/storage.go

@ -4,28 +4,27 @@
------------------------------------------------------------------------------------------------------------------------
*/
package application
package storage
import (
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/dune/dune/internal/components"
"forge.chapril.org/dune/dune/internal/storage/memory"
)
func (app *Application) storage() error {
cs := app.components
func Build(cs *components.Components) (jw.Storage, error) {
impl, err := cs.Config.GetString("storage")
if err != nil {
return err
return nil, err
}
switch impl {
case "memory":
cs.Storage = memory.New()
return nil
return memory.New(), nil
default:
return errors.New( /////////////////////////////////////////////////////////////////////////////////////////////
return nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////////
"this storage implementation does not exist",
"storage", impl,
)
Loading…
Cancel
Save