Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
0d0af33616
  1. 1
      Taskfile.yml
  2. 8
      go.mod
  3. 8
      go.sum
  4. 24
      model.go
  5. 19
      runner.go
  6. 46
      storage.go
  7. 131
      workflow.go

1
Taskfile.yml

@ -6,6 +6,7 @@ version: '3'
tasks:
update:
cmds:
- go get -u forge.chapril.org/losyme/logger
- go mod tidy
lint:
cmds:

8
go.mod

@ -1,3 +1,11 @@
module forge.chapril.org/dune/jw
go 1.17
require forge.chapril.org/losyme/logger v0.0.0-20211005171545-68273525f4af
require (
forge.chapril.org/losyme/buffer v0.0.0-20211003203540-771701f5a518 // indirect
forge.chapril.org/losyme/errors v0.0.0-20211003204336-ad5510c24b40 // indirect
forge.chapril.org/losyme/kvfmt v0.0.0-20211003204256-34ac32764dae // indirect
)

8
go.sum

@ -0,0 +1,8 @@
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/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/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-20211005171545-68273525f4af h1:Eun7tisbfRh2vUA6tfn2wlpYjbla8LElilEBUNSp8p8=
forge.chapril.org/losyme/logger v0.0.0-20211005171545-68273525f4af/go.mod h1:a3fN8yTjq5S/ramr03hIkutKM/35UsijUgRNKHjjlMU=

24
model.go

@ -0,0 +1,24 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "time"
type Model interface {
CreateJob(job *Job) (*Job, error)
NextJob(namespace string) (*Job, error)
UpdateJob(job *Job) (*Job, error)
NotifyJob(id string, data interface{}) error
SetJobPriority(id string, priority Priority) error
SetJobRunAfter(id string, duration time.Duration) error
CreateWorkflow(wf *Workflow) (*Workflow, error)
SetWorkflowPriority(id string, priority Priority) error
}
/*
######################################################################################################## @(°_°)@ #######
*/

19
runner.go

@ -0,0 +1,19 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "forge.chapril.org/losyme/logger"
type Runner interface {
Namespace() string
Model() Model
RunJob(job *Job, logger *logger.Component)
}
/*
######################################################################################################## @(°_°)@ #######
*/

46
storage.go

@ -0,0 +1,46 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "time"
type Stats struct {
Jobs struct {
Todo int
Pending int
Running int
Succeeded int
Failed int
Total int
}
Workflows struct {
Running int
Succeeded int
Failed int
Total int
}
}
type Storage interface {
ValidateJob(job *Job) error
InsertJob(job *Job) (bool, error)
NextJob(namespace string) (*Job, error)
UpdateJob(job *Job) error
NotifyJob(id string, data interface{}) error
SetJobPriority(id string, priority Priority) error
SetJobRunAfter(id string, duration time.Duration) error
ValidateWorkflow(wf *Workflow) error
InsertWorkflow(wf *Workflow, job *Job) error
Workflow(id string, mustExist bool) (*Workflow, error)
UpdateWorkflow(wf *Workflow, job, nextJob *Job) error
SetWorkflowPriority(id string, priority Priority) error
Stats() (*Stats, error)
}
/*
######################################################################################################## @(°_°)@ #######
*/

131
workflow.go

@ -0,0 +1,131 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### jw ####### Copyright (c) 2021 losyme ####################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package jw
import "time"
type Step struct {
Namespace string `json:"namespace"`
Type string `json:"type"`
Config map[string]interface{} `json:"config"`
MaxAttempts int `json:"max_attempts"`
Next map[string]interface{} `json:"next"`
}
// Workflow AFAIRE.
type Workflow struct {
ID string `json:"id"`
Type string `json:"type"`
Description string `json:"description"`
Origin string `json:"origin"`
Priority Priority `json:"priority"`
FirstStep string `json:"first_step"`
AllSteps map[string]*Step `json:"all_steps"`
Data map[string]interface{} `json:"data"`
ExternalID *string `json:"external_id"`
CreatedAt time.Time `json:"created_at"`
Status Status `json:"status"`
FinishedAt *time.Time `json:"finished_at"`
}
func NewWorkflow(firstStep string, allSteps map[string]*Step) *Workflow {
return &Workflow{
FirstStep: firstStep,
AllSteps: allSteps,
}
}
func (wf *Workflow) SetID(value string) *Workflow {
wf.ID = value
return wf
}
func (wf *Workflow) SetType(value string) *Workflow {
wf.Type = value
return wf
}
func (wf *Workflow) SetDescription(value string) *Workflow {
wf.Description = value
return wf
}
func (wf *Workflow) SetOrigin(value string) *Workflow {
wf.Origin = value
return wf
}
func (wf *Workflow) SetPriority(value Priority) *Workflow {
wf.Priority = value
return wf
}
func (wf *Workflow) SetPriorityNone() *Workflow {
return wf.SetPriority(PriorityNone)
}
func (wf *Workflow) SetPriorityLow() *Workflow {
return wf.SetPriority(PriorityLow)
}
func (wf *Workflow) SetPriorityMedium() *Workflow {
return wf.SetPriority(PriorityMedium)
}
func (wf *Workflow) SetPriorityHigh() *Workflow {
return wf.SetPriority(PriorityHigh)
}
func (wf *Workflow) SetPriorityCritical() *Workflow {
return wf.SetPriority(PriorityCritical)
}
func (wf *Workflow) SetData(key string, value interface{}) *Workflow {
if wf.Data == nil {
wf.Data = make(map[string]interface{})
}
wf.Data[key] = value
return wf
}
func (wf *Workflow) SetExternalID(value string) *Workflow {
eID := new(string)
*eID = value
wf.ExternalID = eID
return wf
}
func (wf *Workflow) Fields() []interface{} {
var externalID interface{}
if wf.ExternalID != nil {
externalID = *wf.ExternalID
}
return []interface{}{
"id", wf.ID,
"type", wf.Type,
"description", wf.Description,
"origin", wf.Origin,
"priority", wf.Priority,
"external_id", externalID,
}
}
func (wf *Workflow) Finished() {
now := new(time.Time)
*now = time.Now()
wf.FinishedAt = now
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save