runabol / tork

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

Setting job failed state in Job HandlerFunc #366

Closed jspc closed 6 months ago

jspc commented 7 months ago

Consider the job.HandlerFunc

func erroringHandlerFunc(next job.HandlerFunc) job.HandlerFunc {
    return func(ctx context.Context, et job.EventType, j *tork.Job) (err error) {
        if et == job.Read {
            return next(ctx, et, j)
        }

                return errors.New("some error")
       }
}

When this gets called the logs, as expected, show ERR unexpcted error occurred while processing task error="some error", however the status of the Job remains as PENDING, where I'd expect it to be FAILED.

I've tried to manually update the job to set the expected state, but this seems to be ignored.

Is this a bug, or am I doing something wrong?

runabol commented 7 months ago

I see your point. Generally, middleware is not meant to disrupt the flow of the job/task but only intercept it. An error in a middleware is considered an error in the middleware itself -- not with the job/task itself.

runabol commented 7 months ago

But that being said, you can write a task middleware that sends the the task to the error queue to fail the job.

runabol commented 5 months ago

@jspc thoughts? https://github.com/runabol/tork/pull/424