You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm currently working on a feature that notifies other services when a task has finished.
Unfortunately, I found that asynq doesn't provide an api for this feature.
I currently do this via middleware, but it has some flaws and doesn't work well.
One of the key issues is that the life cycle of the task does not actually end when the middleware is executed.
If another service is notified of the end of the task at this point, however, it may still be active when the other service gets the task status from the inspector.
funcTaskFinishEventMiddleware() asynq.MiddlewareFunc {
returnfunc(h asynq.Handler) asynq.Handler {
returnasynq.HandlerFunc(func(ctx context.Context, t*asynq.Task) error {
vartaskIdstringvarqueueNamestringifval, ok:=asynq.GetQueueName(ctx); ok {
queueName=val
} else {
returnfmt.Errorf("can not get queue name from task context")
}
ifval, ok:=asynq.GetTaskID(ctx); ok {
taskId=val
} else {
returnfmt.Errorf("can not get task id from task context")
}
vartaskErr=h.ProcessTask(ctx, t)
// Send notifications to other services to notify the end of the taskreturntaskErr
})
}
}
Describe the solution you'd like
One solution is to add a global callback function that is called when the task state changes.
Is your feature request related to a problem? Please describe.
I'm currently working on a feature that notifies other services when a task has finished.
Unfortunately, I found that asynq doesn't provide an api for this feature.
I currently do this via middleware, but it has some flaws and doesn't work well.
One of the key issues is that the life cycle of the task does not actually end when the middleware is executed.
If another service is notified of the end of the task at this point, however, it may still be active when the other service gets the task status from the inspector.
Describe the solution you'd like
One solution is to add a global callback function that is called when the task state changes.
Describe alternatives you've considered
I'm currently using middleware, but it's not working well.
The text was updated successfully, but these errors were encountered: