Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
cab840b25e
  1. 1
      Taskfile.yml
  2. 12
      go.mod
  3. 24
      go.sum
  4. 9
      internal/model/jobs.go
  5. 5
      internal/model/model.go
  6. 2
      internal/model/storage.go
  7. 4
      internal/model/validate.go
  8. 67
      internal/model/workflows.go

1
Taskfile.yml

@ -23,6 +23,7 @@ tasks:
- go get -u forge.chapril.org/losyme/logger
- go get -u forge.chapril.org/losyme/minikit
- go get -u forge.chapril.org/losyme/scheduler
- go get -u forge.chapril.org/losyme/util
- go get -u forge.chapril.org/losyme/uuid
- go mod tidy
lint:

12
go.mod

@ -3,16 +3,17 @@ module forge.chapril.org/dune/dune
go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea
forge.chapril.org/dune/sdk v0.0.0-20211121170502-2a68d08470e5
forge.chapril.org/dune/jw v0.0.0-20211124164443-54bdf5007b39
forge.chapril.org/dune/sdk v0.0.0-20211124164826-ed428662ffa0
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
forge.chapril.org/losyme/config v0.0.0-20211124132928-6e36812750b5
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40
forge.chapril.org/losyme/kong v0.0.0-20211102220824-8f8a63ae4cca
forge.chapril.org/losyme/kong v0.0.0-20211124133008-c867a5726aae
forge.chapril.org/losyme/logger v0.0.0-20211119225711-ee831caaf5d4
forge.chapril.org/losyme/minikit v0.0.0-20211119225931-4f3e0dcabbb7
forge.chapril.org/losyme/minikit v0.0.0-20211124133131-020a47b52022
forge.chapril.org/losyme/scheduler v0.0.0-20211003204604-f14dada88faf
forge.chapril.org/losyme/util v0.0.0-20211124132718-3fccea15a31b
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034
)
@ -20,7 +21,6 @@ require (
forge.chapril.org/losyme/buffer v0.0.0-20211003203540-771701f5a518 // indirect
forge.chapril.org/losyme/crypto v0.0.0-20211003213528-e97d4ebea720 // indirect
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae // indirect
forge.chapril.org/losyme/util v0.0.0-20211025142031-fd89d32d86fe // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect

24
go.sum

@ -1,31 +1,31 @@
forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea h1:EC1XXrDQ6E7Oed04iZFKsk2dbxJORBH2G+UxBFz42j4=
forge.chapril.org/dune/jw v0.0.0-20211114170701-4b66b0d705ea/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
forge.chapril.org/dune/sdk v0.0.0-20211121170502-2a68d08470e5 h1:SlZc28AUnQeKn0cNasVO6RoWFdsGp1x2kHJsjY0Pn7Y=
forge.chapril.org/dune/sdk v0.0.0-20211121170502-2a68d08470e5/go.mod h1:MoElZHMrmoc+AH8OXwduGLF+1ls73nS/+3JGx7K8ta4=
forge.chapril.org/dune/jw v0.0.0-20211124164443-54bdf5007b39 h1:rL9AvrSL89tgld9zy31cusqnuo9ORGmd4rCLroiYiC4=
forge.chapril.org/dune/jw v0.0.0-20211124164443-54bdf5007b39/go.mod h1:7CyK2ZvzHntSlOZ7kWcqVhkmUzlE0QI3uKW9kPbNbOY=
forge.chapril.org/dune/sdk v0.0.0-20211124164826-ed428662ffa0 h1:udCkZaAyYeYPL/FutdyipClExeOmh0yJW4sihrfr9Mk=
forge.chapril.org/dune/sdk v0.0.0-20211124164826-ed428662ffa0/go.mod h1:1xvy88D/oZTmcMesjd6UHp7o3DVSsQWZPVcMSBHkoX8=
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=
forge.chapril.org/losyme/buffer v0.0.0-20211003203540-771701f5a518/go.mod h1:4Yl585hmF3bWZfuwGF2Ym8ErykJZiF9yawlmK7szIkc=
forge.chapril.org/losyme/cmdline v0.0.0-20211029192907-e6f74788c44f h1:7m6EpAj3iSvPiRd0mbrxwJ6TI0vMRRrp7M8PFq7AIXI=
forge.chapril.org/losyme/cmdline v0.0.0-20211029192907-e6f74788c44f/go.mod h1:NvAXbqc+LzdATB2GY72fvK4q2EtxxanmrNs03H7+Do4=
forge.chapril.org/losyme/config v0.0.0-20211025142334-51a8a7a73a4f h1:WkVC71+0mHVg8qpgdTvFU9+fcfgY/vMMmzbaIQtJ4DU=
forge.chapril.org/losyme/config v0.0.0-20211025142334-51a8a7a73a4f/go.mod h1:rEfq3F8ofIUiZ5eMsA0ir9ODUT/tSuudsP1qgh8LMiE=
forge.chapril.org/losyme/config v0.0.0-20211124132928-6e36812750b5 h1:XWdCchgnZxRXf7je52XoH9+vLziNzHNP4gfmF7mkNhU=
forge.chapril.org/losyme/config v0.0.0-20211124132928-6e36812750b5/go.mod h1:d3vqLDElRxAwTeCSrlb4Dgcmodmb+bY1UXIsgOBJxJ4=
forge.chapril.org/losyme/crypto v0.0.0-20211003213528-e97d4ebea720 h1:tMwzjPmGvBb5/5Cx0OIPKqT9zMMR6gQn6398rwT0ghc=
forge.chapril.org/losyme/crypto v0.0.0-20211003213528-e97d4ebea720/go.mod h1:zSawWghP8cyqaQNOtKBAWGfAeR93uAyHMqpaXtZJsF8=
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40 h1:EoVVFHoIsWRlecHmXP4kx3ALchz5DAfNwso3gcl/Jbk=
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40/go.mod h1:saYfIRBW9zjiCik+/+5ZaajMEnTPBNI00lF9EnO+2kM=
forge.chapril.org/losyme/kong v0.0.0-20211102220824-8f8a63ae4cca h1:VyGatlviG2GA9xr2U5DdAqJzTvhQvc1MtJR9FRswnz8=
forge.chapril.org/losyme/kong v0.0.0-20211102220824-8f8a63ae4cca/go.mod h1:sOhHc+IcV5vGNnygTML5/P7Ftmlsf9UB2oL+HQRpsYw=
forge.chapril.org/losyme/kong v0.0.0-20211124133008-c867a5726aae h1:a5ws5r6iLJV6SwiB6ru4ZBJH6ZFeldp7pdABLUq1/io=
forge.chapril.org/losyme/kong v0.0.0-20211124133008-c867a5726aae/go.mod h1:zm87kUwqY6/O20Wzl0j2WE/3ZXSHrifghlA1wDjeYow=
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae h1:RdYWXKy+OQNJueb4Qqqo7sL4OY3/TpfUvmoIoH8ua9E=
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae/go.mod h1:wnVjwnCO2vFLLZ1EgFuFws1n8XLluufsGsdozGYSA7c=
forge.chapril.org/losyme/logger v0.0.0-20211119225711-ee831caaf5d4 h1:+5xllpRoYR2wNkBd5FSACEcf7ZSDk6Nm4Y/qFSCvISE=
forge.chapril.org/losyme/logger v0.0.0-20211119225711-ee831caaf5d4/go.mod h1:a3fN8yTjq5S/ramr03hIkutKM/35UsijUgRNKHjjlMU=
forge.chapril.org/losyme/minikit v0.0.0-20211119225931-4f3e0dcabbb7 h1:SNYC9D1fVMOi70shN8XT0PUp0jyR+/9r59ncZV8JTO8=
forge.chapril.org/losyme/minikit v0.0.0-20211119225931-4f3e0dcabbb7/go.mod h1:NdJux6DVhfHaiK+QAc2FV0/fFreh7gMrnuFgySH4Y0s=
forge.chapril.org/losyme/minikit v0.0.0-20211124133131-020a47b52022 h1:AwRJtnKdlHScTvStN4jqbKfmxqkur7K8Q+OZovJh9QQ=
forge.chapril.org/losyme/minikit v0.0.0-20211124133131-020a47b52022/go.mod h1:f5zKGYxV8O3QYDqxlyIENHk1Y93SObrbUIWVNKK2SCg=
forge.chapril.org/losyme/scheduler v0.0.0-20211003204604-f14dada88faf h1:5OIlwVBTdvjCXh2JHAh5rq8FgSe1lXuuKDFtO/ZRaRM=
forge.chapril.org/losyme/scheduler v0.0.0-20211003204604-f14dada88faf/go.mod h1:VNjFKl0Q2vvLDnR9tdNdTIZDLQNlR+gcIGNf2aIYv3o=
forge.chapril.org/losyme/util v0.0.0-20211025142031-fd89d32d86fe h1:xjMUKHxtG8jz57JyOxgNLlRaPLJeQvMV9K3HNlhKDB8=
forge.chapril.org/losyme/util v0.0.0-20211025142031-fd89d32d86fe/go.mod h1:lKYvkuBOTU3E2HuQZDh4ZSA4u3VcFopQbdPUKaHGHEk=
forge.chapril.org/losyme/util v0.0.0-20211124132718-3fccea15a31b h1:5+j6/qkKuv383vxmROry6BgTbU5Fg3VbLaGaiaYew58=
forge.chapril.org/losyme/util v0.0.0-20211124132718-3fccea15a31b/go.mod h1:lKYvkuBOTU3E2HuQZDh4ZSA4u3VcFopQbdPUKaHGHEk=
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034 h1:4NMOPXxwRiXS7wltj2ZZmMO1nFRMPmG1dXK4Ta4MtiM=
forge.chapril.org/losyme/uuid v0.0.0-20211007082235-8d502169e034/go.mod h1:AgvbvGzTkQkbiM+s9eVhvLUSHbA0V6N+q5oBFI2v0LA=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=

9
internal/model/jobs.go

@ -47,10 +47,7 @@ func (m *Model) CreateJob(job *jw.Job) (*jw.Job, error) {
done, err := m.insertJob(job)
if err != nil {
return nil, errors.Wrap( ///////////////////////////////////////////////////////////////////////////////////////
ErrInternal,
errors.WithMessage(err, "unable to insert this job"),
)
return nil, errors.WithMessage(err, "unable to insert this job") ///////////////////////////////////////////////
}
if done {
@ -76,7 +73,6 @@ func (m *Model) updateJob(job *jw.Job) error {
return err
}
/* AFINIR
wf, err := m.Storage.Workflow(*job.Workflow, true)
if err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ -101,7 +97,6 @@ func (m *Model) updateJob(job *jw.Job) error {
return err
}
*/
return nil
}
@ -135,7 +130,7 @@ func (m *Model) UpdateJob(job *jw.Job) (*jw.Job, error) {
break
}
if job.Attempt < job.MaxRetries {
if job.Attempt < job.MaxAttempts {
job.RunAfter = time.Now().Add(jr.Duration)
job.Status = jw.StatusPending
job.Attempt++

5
internal/model/model.go

@ -12,10 +12,7 @@ import (
"forge.chapril.org/losyme/logger"
)
const (
ErrInternal = errors.Sentinel("internal error")
ErrValidation = errors.Sentinel("validation error")
)
const ErrValidation = errors.Sentinel("validation error")
type Model struct {
Storage jw.Storage

2
internal/model/storage.go

@ -19,7 +19,7 @@ func (m *Model) logJob(job *jw.Job) {
"Job to continue",
"id", job.ID,
"run_after", job.RunAfter.Round(time.Second).String(),
"attempt", fmt.Sprintf("%d/%d", job.Attempt, job.MaxRetries),
"attempt", fmt.Sprintf("%d/%d", job.Attempt, job.MaxAttempts),
)
} else {
m.Logger.Info( //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

4
internal/model/validate.go

@ -74,8 +74,8 @@ func (m *Model) validateJob(job *jw.Job) error {
job.Exclusivity = jw.ExclusivityNo
}
if job.MaxRetries < 0 {
job.MaxRetries = 0
if job.MaxAttempts < 0 {
job.MaxAttempts = 0
}
if job.MaxOccurences < 0 {

67
internal/model/workflows.go

@ -7,19 +7,82 @@
package model
import (
"time"
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/errors"
"forge.chapril.org/losyme/util"
"forge.chapril.org/losyme/uuid"
)
func (m *Model) stepToJob(wf *jw.Workflow, name string) (*jw.Job, error) {
step, ok := wf.AllSteps[name]
if !ok {
return nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////////
"this step does not exist",
"step", name,
)
}
job := jw.NewJob(step.Namespace, step.Type).
SetID(uuid.New()).
SetName(name).
SetOrigin(wf.Origin).
SetPriority(wf.Priority).
SetExclusivity(step.Exclusivity).
SetMaxAttempts(step.MaxAttempts).
SetMaxOccurences(step.MaxOccurences)
util.CopyKV(step.Config, job.Private)
job.Workflow = &wf.ID
job.CreatedAt = time.Now()
job.Status = jw.StatusTodo
job.TimeReference = wf.CreatedAt
return job, nil
}
func (m *Model) insertWorkflow(wf *jw.Workflow) error {
job, _ := m.stepToJob(wf, wf.FirstStep)
job.Public = wf.Data
if err := m.Storage.InsertWorkflow(wf, job); err != nil {
m.Logger.Error( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Unable to insert a new workflow",
append(
wf.Fields(),
"reason", err,
)...,
)
return err
}
m.Logger.Info("New workflow [begin]", wf.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
m.Logger.Info("New job", job.Fields()...) //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
return nil
}
func (m *Model) CreateWorkflow(wf *jw.Workflow) (*jw.Workflow, error) {
if err := m.validateWorkflow(wf); err != nil {
return nil, errors.Wrap( ///////////////////////////////////////////////////////////////////////////////////////
ErrValidation,
errors.WithMessage(err, "impossible to create this workflow"),
errors.WithMessage(err, "unable to create this workflow"),
)
}
return nil, nil
if err := m.insertWorkflow(wf); err != nil {
return nil, errors.WithMessage(err, "unable to insert this workflow") //////////////////////////////////////////
}
return wf, nil
}
func (m *Model) updateWorkflow(wf *jw.Workflow, job *jw.Job) error {
return nil
}
func (m *Model) SetWorkflowPriority(id string, priority jw.Priority) error {

Loading…
Cancel
Save