Job release and duplicate entries during model update

Posted 3 months ago by lambooni

I have a strange issue related to releasing jobs and model update throwing duplicate entry errors. If I run the code with the release in, I get the error. Remove the release from the job and all runs fine.

My job is as follows:

    public function handle(LinnworksService $linnworksService)
    {
        try{
            $linnworksService->getFullOrdersById($this->id_array);
        } catch(\Exception $e){
            \Sentry::captureException($e);
        $this->release(60);
        }
    }

Generally a fail on the job happens due to an API connection error within the Linnworks API (throttle, server down etc.)

The script which fails creates the duplicate entry error (simplified):

$model = Model::where('source_id', $source_id)->where('source', $source)->first();
if(isset($model)) $model->update($data);

The very strange thing is that the duplicate entry is on the keys for which I am searching for table_source_id_source_unique;

As I say, I have fixed this by removing the release but I am curious as to why this may be occurring.

Please sign in or create an account to participate in this conversation.