SAAS-854 - celery-based SoundCloud backend uploader
This commit is contained in:
parent
80bfb7fd93
commit
49165e91d9
12 changed files with 672 additions and 12 deletions
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
require_once 'php-amqplib/amqp.inc';
|
||||
require_once 'massivescale/celery-php/celery.php';
|
||||
|
||||
class Application_Model_RabbitMq
|
||||
{
|
||||
public static $doPush = false;
|
||||
|
||||
const CELERY_TIMEOUT = 10;
|
||||
|
||||
/**
|
||||
* Sets a flag to push the schedule at the end of the request.
|
||||
*/
|
||||
|
@ -42,6 +45,32 @@ class Application_Model_RabbitMq
|
|||
$conn->close();
|
||||
}
|
||||
|
||||
public static function sendCeleryMessage($task, $exchange, $data) {
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$c = new Celery($CC_CONFIG["rabbitmq"]["host"],
|
||||
$CC_CONFIG["rabbitmq"]["user"],
|
||||
$CC_CONFIG["rabbitmq"]["password"],
|
||||
$CC_CONFIG["rabbitmq"]["vhost"],
|
||||
$exchange=$exchange);
|
||||
$result = $c->PostTask($task, $data);
|
||||
|
||||
$timeout = 0;
|
||||
while(!$result->isReady()) {
|
||||
sleep(1);
|
||||
if($timeout++ >= self::CELERY_TIMEOUT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($result->isSuccess()) {
|
||||
Logging::info($result);
|
||||
return $result->getResult();
|
||||
} else {
|
||||
throw new CeleryTimeoutException("Celery task $task timed out!");
|
||||
}
|
||||
}
|
||||
|
||||
public static function SendMessageToPypo($event_type, $md)
|
||||
{
|
||||
$md["event_type"] = $event_type;
|
||||
|
@ -146,5 +175,9 @@ class Application_Model_RabbitMq
|
|||
|
||||
public static function SendMessageToHaproxyConfigDaemon($md){
|
||||
//XXX: This function has been deprecated and is no longer needed
|
||||
}
|
||||
}
|
||||
|
||||
public static function uploadToSoundCloud($data) {
|
||||
return self::sendCeleryMessage("upload", "soundcloud-uploads", $data);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue