dimanche 24 juin 2018

Laravel Queue Standalone "isDownForMaintenance" Error

I'm using Laravel's queue as a standalone and I got everything to run except this one error I keep getting.

PHP Fatal error: Uncaught Error: Call to undefined method Illuminate\Container\Container::isDownForMaintenance()

On Laravel's forum there was a fix posted a year ago, but it doesn't seem to work. The solution was

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

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

Doesn't anyone have a solution for this?

The entire code is:

<?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);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire