<?php
namespace Jobs\Model;

class MQueue
{
    public static function getQueue(array $config, $logger)
    {
        $classQueue = $config['class'] ?: 'Jobs\Model\Queue\MRedisTopicQueue';
        if (is_callable([$classQueue, 'getConnection'])) {
            //最多尝试连接3次
            for ($i=0; $i < 3; $i++) {
                $connection = $classQueue::getConnection($config, $logger);
                if ($connection && is_object($connection)) {
                    break;
                }else{
                    $logger->log("connect...,retry=".($i+1), 'error');
                }
            }

            return $connection;
        }
        echo 'you must add queue config' . PHP_EOL;
        exit;
    }
}