Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

php - Laravel Job fails during execution: method_exists()

We are running on Laravel 6 and we have got the following problem. A job we execute, that counts the number of impressions and clics of certain images triggers the following error, due to a high number of calls to the function:

method_exists(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "AppJobsRegisterHouseLog" of the object you are trying to operate on was loaded before unserialize() gets called or provide an autoloader to load the class definition

We already increased the number of tries so it executes after sometime, so it's not the actual problem, but it sends an error to our error logs (Slack Channel) and causes a lot of "spam".

I was trying to fix the above error but I wasn't able to fix it, so at least I tried to "mute" the notification through an "failed job exception" but still to it fails.

The best would be to resolve the actual problem, the second best would be to mute it. Anyone could help?

The Job:

<?php

namespace AppJobs;

use AppHouseLog;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;
use IlluminateSupportFacadesLog;
use Exception;

class RegisterHouseLog implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 20;

    public $house_id;
    public $user_id;
    public $date;
    public $type;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($house_id,$user_id,$type, $date)
    {
        $this->house_id = $house_id;
        $this->user_id = $user_id;
        $this->type = $type;
        $this->date = $date;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $log = new HouseLog();
        $log->user_id = $this->user_id;
        $log->house_id = $this->house_id;
        $log->type = $this->type;
        $log->date = $this->date;
        $log->save();
    }

    public function failed(Exception $exception)
    {
        Log::critical('Failed Register House');
    }
}

And the call:

<?php

namespace AppHttpControllersapi;

use AppHouseLog;
use IlluminateHttpRequest;
use AppHttpControllersController;
use AppJobsRegisterHouseLog;
use CarbonCarbon;

class HouseLogController extends Controller
{
    public function registerLog(Request $request)
    {
            $date = Carbon::now();
            RegisterHouseLog::dispatch($request->house_id, $request->user_id, $request->type, $date);
    }
}

Thanks a lot!!

question from:https://stackoverflow.com/questions/65599426/laravel-job-fails-during-execution-method-exists

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This error is likely due to the job dispatcher not being able to resolve AppJobsRegisterHouseLog when it pulls from the job queue to kick off a job.

Try clearing the class loader cache:

artisan cache:clear

Also try restarting your job dispatcher process.

artisan queue:restart

It may not be the best solution, but you could also fix this by removing implements ShouldQueue from your job class definition; it would make the job kick off right away without going through the queue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...