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
Currently, I'm using a model updated event with a listener which (in turn) fires off a chain of jobs. Each job takes the model in their constructor and can update the model's status so the end user can see the state of the model.
What I was seeing is when I updated the model from my controller (which ultimately calls this chain of jobs), it all worked fine with the chain being called. However, then updating the status of the model inside the chain of jobs fires off another chain, exponentially increasing.
I then changed the model's updateOrFail() within the jobs to updateQuietly(), which resolved the issue but left me with additional repeated code to translate the now boolean return value into an exception on failure, which the job then continues to handle 'out of the box'.
My Solution:
Adding a saveQuietlyOrFail() and updateQuietlyOrFail() method to the Illuminate\Database\Eloquent\Model class which allows a save/update to not fire off events but to also have the built in exception throwing to make use of Laravel's great exception handling.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My Use Case:
Currently, I'm using a model
updated
event with a listener which (in turn) fires off a chain of jobs. Each job takes the model in their constructor and can update the model's status so the end user can see the state of the model.What I was seeing is when I updated the model from my controller (which ultimately calls this chain of jobs), it all worked fine with the chain being called. However, then updating the status of the model inside the chain of jobs fires off another chain, exponentially increasing.
I then changed the model's
updateOrFail()
within the jobs toupdateQuietly()
, which resolved the issue but left me with additional repeated code to translate the now boolean return value into an exception on failure, which the job then continues to handle 'out of the box'.My Solution:
Adding a
saveQuietlyOrFail()
andupdateQuietlyOrFail()
method to theIlluminate\Database\Eloquent\Model
class which allows a save/update to not fire off events but to also have the built in exception throwing to make use of Laravel's great exception handling.Beta Was this translation helpful? Give feedback.
All reactions