Laravel 5.4:队列作业失败,出现'Illuminate \ Database \ Eloquent \ ModelNotFoundException',并显示消息'没有模型的查询结果[App \ message]'

时间:2017-08-22 13:16:34

标签: php laravel queue

我正在使用private final int MAX_SMS_IN_ONE_TIME = 10; private final int DELAY_BETWEEN_CHUNKS = 5000; public void sendMessage(arguments){ // Send long messages in chunk of 20 messages and put gap of increasing 5 seconds till 50 seconds and then reset. final Iterator iterator = messageChunks.iterator(); new Thread(new Runnable() { @Override public void run(){ int interval =1; while (iterator.hasNext()) { for (final Contact contact : (List<Contact>) iterator.next()) { sendSMS(body, contact.getmMobileNumbers().get(0)); App.trackEvent("Message", "Sent", "Messages from our sms app"); } } try { Log.i("chunk", "chunk # " + interval + " delay is " + DELAY_BETWEEN_CHUNKS); Thread.sleep(DELAY_BETWEEN_CHUNKS * interval); interval++; if (interval == 10) { interval = 1; } } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } public void sendSMS(final String message, final String phoneNo) { try { String SENT = "com.ebryx.smscustommessagegeneration"+""+System.currentTimeMillis()+""+((int)this.getmMessageId()); Intent intentMessageASendStatus = new Intent(SENT); final PendingIntent pi = PendingIntent.getBroadcast(App.getContext(), ((int)this.getmMessageId()), intentMessageASendStatus, PendingIntent.FLAG_CANCEL_CURRENT); final ArrayList<PendingIntent> sentPI = new ArrayList<PendingIntent>(){{add(pi);}}; App.getContext().registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Log.i("tag","sent successfully "); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Log.i("tag","Generic Failure"); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Log.i("tag","No service failure"); break; case SmsManager.RESULT_ERROR_NULL_PDU: break; case SmsManager.RESULT_ERROR_RADIO_OFF: Log.i("tag","Airplane mode failure"); break; } } }, new IntentFilter(SENT)); final SmsManager smsManager = SmsManager.getDefault(); final ArrayList<String> parts = smsManager.divideMessage(message); new Timer().schedule(new TimerTask() { @Override public void run() { smsManager.sendMultipartTextMessage(phoneNo, null, parts, sentPI, null); }}, 3000); } } catch (Exception e) { e.printStackTrace(); } } Laravel 5.4来创建批量插入和APi调用的作业。每当我从Queue调用API时,它都会执行脚本但是处理失败并且异常

  

Illuminate \ Database \ Eloquent \ ModelNotFoundException',消息为“No   查询模型[App \ message]'的结果   C:\ XAMPP \ htdocs中\阿布舍克巴克\ SMS \ SMS_rest_dev \厂商\ laravel \框架\ SRC \照亮\数据库\锋\ Builder.php:312

Postman

我的MessageController.php(控制器文件)

> Stack trace:
> #0 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(46):
> Illuminate\Database\Eloquent\Builder->findOrFail(NULL)
> #1 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(42):
> App\Jobs\createmessage->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
> #2 [internal function]: App\Jobs\createmessage->__wakeup()
> #3 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(38):
> unserialize('O:22:"App\\Jobs\\...')
> #4 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(69):
> Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob),
> Array)
> #5 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(317):
> Illuminate\Queue\Jobs\Job->fire()
> #6 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(267):
> Illuminate\Queue\Worker->process('database',
> Object(Illuminate\Queue\Jobs\DatabaseJob),
> Object(Illuminate\Queue\WorkerOptions))
> #7 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(224):
> Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob),
> 'database', Object(Illuminate\Queue\WorkerOptions))
> #8 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102):
> Illuminate\Queue\Worker->runNextJob('database', 'default',
> Object(Illuminate\Queue\WorkerOptions))
> #9 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86):
> Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
> #10 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
> #11 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(30):
> call_user_func_array(Array, Array)
> #12 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87):
> Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
> #13 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31):
> Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application),
> Array, Object(Closure))
> #14 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Container\Container.php(539):
> Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application),
> Array, Array, NULL)
> #15 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Console\Command.php(182): Illuminate\Container\Container->call(Array)
> #16 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\symfony\console\Command\Command.php(264):
> Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Illuminate\Console\OutputStyle))
> #17 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Console\Command.php(168): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Illuminate\Console\OutputStyle))
> #18 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\symfony\console\Application.php(874):
> Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Symfony\Component\Console\Output\ConsoleOutput))
> #19 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\symfony\console\Application.php(228):
> Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand),
> Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Symfony\Component\Console\Output\ConsoleOutput))
> #20 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\symfony\console\Application.php(130):
> Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Symfony\Component\Console\Output\ConsoleOutput))
> #21 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122):
> Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Symfony\Component\Console\Output\ConsoleOutput))
> #22 C:\xampp\htdocs\Abhishek\SMS\SMS_rest_dev\artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput),
> Object(Symfony\Component\Console\Output\ConsoleOutput))
> #23 {main}

我的工作类文件

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\message;
use App\template;
use Illuminate\Support\Facades\DB;
use App\API\ApiHelper;
use App\Repos\Repository;
use GuzzleHttp\Client;
use App\Jobs\createmessage;

class MessageController extends Controller
{
    use ApiHelper;
    protected $model;
    protected $mes;
    public function __construct(message $message)
    {    
        $this->model = new Repository( $message );
        $this->mes = $message;
        $this->middleware('auth:api'); 
    }

    public function store(Request $request)
    {
        dispatch(new createmessage ($this->mes));  
    }
}

我的留言文件(型号)

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\API\ApiHelper;
use App\Repos\Repository;
use GuzzleHttp\Client;
use App\message;
use App\template;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class createmessage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use ApiHelper;
    protected $model;

    public $tries = 2;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(message $message)
    {
        $this->model = $message;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Request $request)
    {

        $use_id = $request->user()->id;

        foreach($request->data as $temp)
        {
            //code
        }

        return  response()->json($sms, 201);

    }
}

我的api.php(路线档案)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class message extends BaseModel
{
    protected $table = 'message';
    //public $timestamps = false;
    public $primaryKey = 'message_id';
    protected $fillable =['message_id', 'user_id','template_id', 'sender_id', 'params', 'message', 'cost', 'phone_number'];
    const CREATED_AT = 'created_on';
    const UPDATED_AT = 'updated_on';


    public function user()
    {
        return $this->belongsTo(user::class)->select('id', 'name');
    }

    public function message_template()
    {
        return $this->belongsTo(template::class)->select('template_id', 'template', 'type');
    }

}

我试图在Laravel中跟随documentation队列。如果需要其他信息,将提供。 任何帮助将不胜感激。感谢

0 个答案:

没有答案