Is it possible to pass a failure callback to a job when queueing it? #47410
-
I'm aware that you can implement the
I expect that my job may be called in different contexts, and may want to clean up based on that context, rather than having a generic cleanup. An example is a job to send an email when something is created. The first time it runs, if it fails, I would want to change the status on the model back to "draft" or "failed". But, if I allow the user to resend the email at a later time and this fails, the model has already been created so I don't want to change the status on failure. I would much prefer that this logic was baked into the actions that allow for sending, and not the job itself knowing the context that it is called in. I hope that makes sense! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It's possible with batches. Not with a single Job. But you can incorporate the logic yourself in the Job. Just pass your closure in to the dispatch method, which will pass it to your constructor. |
Beta Was this translation helpful? Give feedback.
It's possible with batches. Not with a single Job. But you can incorporate the logic yourself in the Job. Just pass your closure in to the dispatch method, which will pass it to your constructor.