Created
December 8, 2023 08:54
-
-
Save Pirosauro/62545d0c957e10b52083df5a928af329 to your computer and use it in GitHub Desktop.
tork Job middleware #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"os" | |
"github.com/runabol/tork/cli" | |
"github.com/runabol/tork/conf" | |
"github.com/runabol/tork/engine" | |
"github.com/rs/zerolog/log" | |
"github.com/runabol/tork" | |
"github.com/runabol/tork/middleware/job" | |
) | |
func main() { | |
if err := conf.LoadConfig(); err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
mw := func(next job.HandlerFunc) job.HandlerFunc { | |
return func(ctx context.Context, et job.EventType, j *tork.Job) error { | |
log.Debug(). | |
Msgf("received job %s at state %s (%s)", j.ID, j.State, et) | |
return next(ctx, et, j) | |
} | |
} | |
engine.RegisterJobMiddleware(mw) | |
if err := cli.New().Run(); err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
} |
Successful job
name: my job
tasks:
- name: my first task
run: echo hello world
- name: do some real work
run: sleep 5
- name: my second task
run: echo bye world
Relevant output from middleware (no STATE_CHANGE -> RUNNING)
"level":"debug","time":1702026162,"message":"received job dd1349b191cf4840afa3ead0655efabb at state PENDING (STATE_CHANGE)"}
{"level":"debug","time":1702026162,"message":"received job dd1349b191cf4840afa3ead0655efabb at state RUNNING (READ)"}
{"level":"debug","time":1702026163,"message":"received job dd1349b191cf4840afa3ead0655efabb at state RUNNING (READ)"}
{"level":"debug","time":1702026167,"message":"received job dd1349b191cf4840afa3ead0655efabb at state COMPLETED (STATE_CHANGE)"}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Job with a failed task
Relevant output from middleware (no RUNNING state)