#Dispatched Job Fails in Horizon Due to ModelNotFoundException
29 messages · Page 1 of 1 (latest)
We are facing this very frequently in the production server
We are using Valkey cache,laravel horizon
The data in the Db and not soft deleted as well
Yeah it marked as failed well but when we retry using the same payload then it works
when we query in db we found the data there
Then you must have a race condition somehow
Can’t really help without seeing the code
The issue occurs when we pass the full Model instance as a parameter to the job it no longer works. However, if we pass only the model ID, it works correctly. This behaviour was working as expected previously. The problem started after upgrading the server from 2GB to 4GB RAM. We’ve identified the pattern, but the root cause is still unclear it seems unusual, but something in the upgrade likely triggered this change.
It’ll be unrelated to the ram upgrade, that’s a red herring
I understand. There haven’t been any major code changes; it was working as expected before, but now it isn’t. What could be the potential cause, and is there a workaround?
I’m not fully familiar with the package but eloquent models are serialized into just their ids, put into the job payload, then re retrieved when running the job. That’s where this is originating from
There must’ve been a change somewhere, it wouldn’t just break
Unless you’re doing more in those jobs like findOrFail, do you have the full stack trace?
This isn’t limited to a single job; most of the jobs are showing the same behaviour.
yeah i will share shortly
Could you show how you’re dispatching these?
It’s as if you’re dispatching before the model gets committed, like if you’re in a transaction
The model then saves, the job is retrying and marks itself as failed afterwards
Alright now we’re going down a rabbit hole, when does that listener get fired
Well that shouldn’t matter, sorry I’m trying to help you debug while walking home
Thank you ❤️ for your help with this. I tried for days on the server to identify the issue, but I couldn’t find the root cause or its source.
I’d recommend putting some basic logging around for whether the dispatch is sitting in an unclosed transaction (even across jobs), try retrieve the model straight after dispatch etc
sure will do thank you