Laravel队列独立“ isDownForMaintenance”错误

时间:2018-06-24 14:42:33

标签: php laravel-5 laravel-queue

我将Laravel的队列作为独立队列使用,除了我不断遇到的一个错误之外,我已经可以运行所有东西。

  

PHP致命错误:未捕获错误:调用未定义方法   Illuminate \ Container \ Container :: isDownForMaintenance()

一年前,在Laravel的论坛上发布了一个修复程序,但是似乎没有用。解决方案是

<?php 
use Illuminate\Container\Container as IlluminateContainer;

class Container extends IlluminateContainer {   
     public function isDownForMaintenance() {
           return false;   
     } 
}

没有人对此有解决方案吗?

整个代码是:

<?php

use \Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Queue\Capsule\Manager as QueueManager;
use Illuminate\Redis\Database;
use Illuminate\Queue\Worker;
use Illuminate\Events\Dispatcher;
use Illuminate\Queue\WorkerOptions;
use Illuminate\Container\Container as IlluminateContainer;

require __DIR__ . '/../../../vendor/autoload.php';
//require __DIR__ . '/Main.php';
//require __DIR__ . '/Fix.php';


class Container extends IlluminateContainer
{
  public function isDownForMaintenance() {
    return false;
  }
}


class TasksDomain
{
    public function fire($job, $asssetID)
    {
        // Task for domain
        $domain = DomainsMongo::collection('domains')->where('_id', $assetID)->first();
        echo $domain->Domain;
    }
}

class MyQueueException implements ExceptionHandler
{
    /**
     * Report or log an exception.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(\Exception $e)
    {
        //处理异常
    }
    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function render($request, \Exception $e)
    {
    }
    /**
     * Render an exception to the console.
     *
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @param  \Exception  $e
     * @return void
     */
    public function renderForConsole($output, \Exception $e)
    {
        $this->report($e);
    }
  }

  $queue = new QueueManager;

  $container = $queue->getContainer();

  $container['config']['database.redis'] = [
    'client' => 'predis',
    'cluster' => false,
    'default' => [
        'host' => getenv('REDIS_HOST'),
        'port' => getenv('REDIS_PORT'),
        'password' => getenv('REDIST_PASSWORD'),
        'database' => 0,
    ],
  ];

  $container->singleton('redis', function ($container) {
    return new Database($container['config']['database.redis']);
  });

  $container['config']["queue.connections.redis"] = [
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => 'default',
    'retry_after' => 30,
  ];

  $queue->addConnection([
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => 'default',
    'retry_after' => 30,
  ]);

  $queue->setAsGlobal();

  $dispatcher = new Dispatcher();
  $worker = new Worker($queue->getQueueManager(), $dispatcher, new IntelX\Library\Tasks\TasksQueueException());
  $options = new WorkerOptions();
  $options->maxTries = 3;
  $options->timeOut = 300;
  $worker->daemon('redis', 'default', $options);

1 个答案:

答案 0 :(得分:0)

找到了答案!我将其发布给未来的开发人员,因为LaraCasts上的解决方案不起作用!

解决方案:

use Illuminate\Container\Container;
use Illuminate\Queue\Capsule\Manager as QueueManager;

class Application extends Container
{
    public function isDownForMaintenance()
    {
        return false;
    }
}

$queue = new QueueManager(new Application());