Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUNNING state change not shown on middleware #291

Closed
Pirosauro opened this issue Dec 8, 2023 · 1 comment
Closed

RUNNING state change not shown on middleware #291

Pirosauro opened this issue Dec 8, 2023 · 1 comment

Comments

@Pirosauro
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant