Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #107 from ergonlogic/conn-exception
Browse files Browse the repository at this point in the history
Fixes #106: Introduce CeleryConnectionException
  • Loading branch information
gjedeer authored May 30, 2017
2 parents 3b2865a + c45ef16 commit 7c9ec2b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/CeleryAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Celery;

use PhpAmqpLib\Exception\AMQPProtocolConnectionException;

/**
* Client for a Celery server - abstract base class implementing actual logic
* @package celery-php
Expand Down Expand Up @@ -57,10 +59,24 @@ public function BuildConnection($connection_details, $is_backend = false)
}
}

/**
* @throws CeleryConnectionException on connection failure.
*/
public static function InitializeAMQPConnection($details)
{
$amqp = AbstractAMQPConnector::GetConcrete($details['connector']);
return $amqp->GetConnectionObject($details);
try {
return $amqp->GetConnectionObject($details);
}
catch (AMQPProtocolConnectionException $e) {
throw new CeleryConnectionException("Failed to establish a AMQP connection. Check credentials.");
}
catch (\ErrorException $e) {
throw new CeleryConnectionException("Failed to establish a AMQP connection. Check hostname.");
}
catch (Exception $e) {
throw new CeleryConnectionException("Failed to establish a AMQP connection. Unspecified failure.");
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/CeleryConnectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Celery;

/**
* Emited by CeleryAbstract::PostTask() connection failures etc
* @package celery-php
*/
class CeleryConnectionException extends CeleryException
{
}

0 comments on commit 7c9ec2b

Please sign in to comment.