hibiken / asynq

Simple, reliable, and efficient distributed task queue in Go
MIT License
10k stars 714 forks source link

[FEATURE REQUEST] Task callbacks #783

Open agorman opened 1 year ago

agorman commented 1 year ago

Is your feature request related to a problem? Please describe. I'd like to be able to get TaskInfo when a task starts or stops. In my application I'm storing task history and results but need them to go in an on disk database.

Describe the solution you'd like One possible solution would be to pass a callback function to the Config when creating a NewServer. Ideally the callback function would pass a TaskInfo object. The callback would fire when when a task starts processing or stops processing. It could also fire on state change or whatever makes sense.

Obviously this would cause overhead to a worker but only if a callback function was passed. In that case it should be up to the caller to ensure that the time spent in the callback was acceptable to them.

Describe alternatives you've considered I've tried to handle this by sending job information to a message queue in middleware but inside middleware the job state will always be TaskStateActive and I can't see things like errors or results.

ghstahl commented 10 months ago

I would like to know the current retry in the taskinfo. Maybe this would cover an ask I would like. I don't want any of my tasks archived. So when I get a handle task callback It would be nice to get the current retry, max-retry so that I can eat the error and return nil.