Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
2.3 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### demo ####### Copyright (c) 2021 mls-361 #################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package demo
import (
"time"
"forge.chapril.org/armen/runner"
"forge.chapril.org/armen/workers"
"forge.chapril.org/armen/armen/internal/components"
)
type demo struct {
logger components.Logger
pool *workers.Pool
}
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
}
if v, ok := ccs.Application.LookupEnv("DEMO"); !ok || v != "t" && v != "true" {
return nil
}
d := &demo{
logger: ccs.Logger,
}
r := runner.New("demo", ccs.Model)
if err := r.AddJobHandler("panic", runner.JHF(d.panic)); err != nil {
return err
}
if err := r.AddJobHandler("pending", runner.JHF(d.pending)); err != nil {
return err
}
if err := r.AddJobHandler("succeeded", runner.JHF(d.succeeded)); err != nil {
return err
}
p, err := workers.NewPool(&workers.Config{
Logger: ccs.Logger,
Model: ccs.Model,
Runner: r,
PoolSize: 2,
Host: ccs.Application.Host(),
})
if err != nil {
return err
}
d.pool = p
_demo = d
return nil
}
func Start() {
if _demo == nil {
return
}
_demo.pool.Start()
_demo.logger.Notice("Demonstration mode is activated") //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
}
func Stop() {
if _demo == nil {
return
}
_demo.pool.Stop()
}
/*
######################################################################################################## @(°_°)@ #######
*/