Callback upon process completion. Any ideas?

The short version: is there an event that I can register to if I want to determine if a process (web or console) finished without an error?

The long version: I have a heavy process that performs a lot of operations and also sends emails, but I don’t want the emails to be sent until the entire process finishes without an error. So I was thinking of building a process-level email queue, and then to listen to an event that would indicate whether the action completed successfully, and only then send the emails in the queue.

It’s kind of like a database transaction solution but for outgoing emails.

Any ideas?


Too little information on your implementation.

I guess everything is in yii2 framework.

How do you manage the heavy process? (Yii2 queue, custom yii2 implementation, from script…)

Why can’t you queue all email and send them at the end if everything is OK?