Browse Source

En cours de développement

master
mls-361 7 months ago
parent
commit
c3f9164364
  1. 35
      internal/demo/demo.go
  2. 76
      internal/demo/jobs.go

35
internal/demo/demo.go

@ -7,8 +7,6 @@
package demo
import (
"time"
"forge.chapril.org/armen/runner"
"forge.chapril.org/armen/workers"
@ -22,35 +20,6 @@ type demo struct {
var _demo *demo
func (d *demo) panic(_ *runner.Job) {
panic("it's only a test") //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
func (d *demo) pending(job *runner.Job) {
v, ok := job.Private["key"]
if ok {
value, ok := v.(int)
if ok {
if value == 3 {
// end
return
}
job.SetPrivate("key", value+1)
} else {
job.Failed().SetError("bug")
}
} else {
job.SetPrivate("key", 0)
}
job.Pending().SetDuration(time.Second)
}
func (d *demo) succeeded(_ *runner.Job) {
// nothing to do
}
func Build(ccs *components.Components) error {
if _, ok := ccs.Application.LookupEnv("CONFIG"); ok {
return nil
@ -78,6 +47,10 @@ func Build(ccs *components.Components) error {
return err
}
if err := r.AddJobHandler("workflow", runner.JHF(d.workflow)); err != nil {
return err
}
p, err := workers.NewPool(&workers.Config{
Logger: ccs.Logger,
Runner: r,

76
internal/demo/jobs.go

@ -0,0 +1,76 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### demo ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package demo
import (
"time"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/runner"
)
func (d *demo) panic(_ *runner.Job) {
panic("it's only a test") //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
func (d *demo) pending(job *runner.Job) {
v, ok := job.Private["count"]
if ok {
count, ok := v.(int)
if ok {
if count == 3 {
// end
return
}
job.SetPrivate("count", count+1)
} else {
job.Failed().SetError("bug")
}
} else {
job.SetPrivate("count", 0)
}
job.Pending().SetDuration(time.Second)
}
func (d *demo) succeeded(_ *runner.Job) {
// nothing to do
}
func (d *demo) workflow(job *runner.Job) {
allSteps := map[string]*jw.Step{
"stepA": &jw.Step{
Namespace: "demo",
Type: "succeeded",
Next: map[string]interface{}{"succeeded": "stepB"},
},
"stepB": &jw.Step{
Namespace: "demo",
Type: "pending",
},
}
_, err := job.Factory.NewWorkflow("stepA", allSteps).
SetDescription("Demonstration worflow").
SetOrigin("demo").
CreateWorkflow()
if err != nil {
job.Logger.Error( //////////////////////////////////////////////////////////////////////////////////////////////
"Create workflow error",
"reason", err,
)
job.Failed().SetError(err.Error())
return
}
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save