runabol / tork

A distributed workflow engine
https://tork.run
MIT License
599 stars 40 forks source link

RUNNING state change not shown on middleware #291

Closed Pirosauro closed 11 months ago

Pirosauro commented 11 months ago

Playing with a job middleware, I met a behaviour which I'm not quite sure. My dummy code is:

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)
    }
}

Following, I added a job which will fail:

name: my failing job
tasks:
  - name: my first task
    run: echo hello world
  - name: raise an error
    run: exit 1
  - name: my second task
    run: echo bye world

And, from the middleware, I got:

{"level":"debug","time":1702025778,"message":"received job ed83c87901d24b14a7ed44735b130a8a at state PENDING (STATE_CHANGE)"} ... {"level":"debug","time":1702025778,"message":"received job ed83c87901d24b14a7ed44735b130a8a at state FAILED (STATE_CHANGE)"} {"level":"debug","time":1702025779,"message":"received job ed83c87901d24b14a7ed44735b130a8a at state FAILED (READ)"} ... {"level":"debug","time":1702026006,"message":"received job ed83c87901d24b14a7ed44735b130a8a at state FAILED (READ)"}

But what I'm expecting is also a RUNNING (STATE_CHANGE). Am I wrong? Does it also happen to you or am I missing something? A similar result also got with a successful job (https://gist.github.com/Pirosauro/62545d0c957e10b52083df5a928af329)

Pirosauro commented 11 months ago

the latest version (0.1.62) with updated dependencies, works as expected and doesn't have the issue above. My test was on 0.1.57