timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.15k stars 160 forks source link

onComplete alternative #517

Open lramirez925 opened 1 month ago

lramirez925 commented 1 month ago

Looking at upgrading to v10, but having issues wrapping my head around how to replace my onComplete scenario. Is that flow no longer supported at all going forward or am I just blind?

Currently I have workflow system that adds an "onComplete" that looks up the next job to run and schedules it. I prefer to have it separate from the actual job code. Just making sure I am not missing a new similar flow that I could use before rebuilding it.

timgit commented 1 month ago

onComplete was removed in v10 and I'm not currently planning on bringing them back. Dead letter queues handle the majority use case of orchestration of the failure completion state.

lramirez925 commented 1 month ago

You mention dead letter queues but that would only be able to handle performing actions when jobs fail correct?

So there isn't any way to handle successful job lifecycles on a queue in any way for the foreseeable future?

eric-gonzalez-tfs commented 3 weeks ago

You mention dead letter queues but that would only be able to handle performing actions when jobs fail correct?

So there isn't any way to handle successful job lifecycles on a queue in any way for the foreseeable future?

@lramirez925 - I also needed this functionality and implemented a workaround. My goal was to track the success, failure, and retry metrics for each of my jobs.

To achieve this, I created a wrapper function that surrounds each job before instantiation. This wrapper awaits the execution of the actual job handler, catching and re-throwing any errors that occur to retain pg-boss error handling functionality.

Depending on the outcome (success or error), the wrapper then creates a new job dedicated to monitoring the job state.

From my experience, while pg-boss DLQs are effective for handling failed jobs, they fall short in tracking successful and retried jobs. An onComplete alternative would be very useful for this purpose.