MQueue.Class.php 730 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace Jobs\Model;
  3. class MQueue
  4. {
  5. public static function getQueue(array $config, $logger)
  6. {
  7. $classQueue = $config['class'] ?: 'Jobs\Model\Queue\MRedisTopicQueue';
  8. if (is_callable([$classQueue, 'getConnection'])) {
  9. //最多尝试连接3次
  10. for ($i=0; $i < 3; $i++) {
  11. $connection = $classQueue::getConnection($config, $logger);
  12. if ($connection && is_object($connection)) {
  13. break;
  14. }else{
  15. $logger->log("connect...,retry=".($i+1), 'error');
  16. }
  17. }
  18. return $connection;
  19. }
  20. echo 'you must add queue config' . PHP_EOL;
  21. exit;
  22. }
  23. }