diff --git a/airtime_mvc/application/common/TaskManager.php b/airtime_mvc/application/common/TaskManager.php index 415afa55f..aa250f294 100644 --- a/airtime_mvc/application/common/TaskManager.php +++ b/airtime_mvc/application/common/TaskManager.php @@ -67,10 +67,8 @@ final class TaskManager { try { $lock = $this->_getLock(); if ($lock && microtime(true) < $lock['valstr'] + self::TASK_INTERVAL_SECONDS) { - // Fun fact: Propel caches the database connection and uses it persistently - // (thus why calling Propel::getConnection explicitly and passing a connection - // parameter is often not necessary when making Propel queries). Long story short, - // if we don't use commit() here, we end up blocking other queries made within this request + // Propel caches the database connection and uses it persistently, so if we don't + // use commit() here, we end up blocking other queries made within this request $this->_con->commit(); return; } diff --git a/airtime_mvc/application/services/CeleryService.php b/airtime_mvc/application/services/CeleryService.php index 9f21af3e4..ad18a56b1 100644 --- a/airtime_mvc/application/services/CeleryService.php +++ b/airtime_mvc/application/services/CeleryService.php @@ -50,8 +50,6 @@ class CeleryService { * * @return string the task identifier for the started Celery task so we can fetch the * results asynchronously later - * - * @throws CeleryException when no message is found */ public static function sendCeleryMessage($task, $exchange, $data) { $config = parse_ini_file(Application_Model_RabbitMq::getRmqConfigPath(), true); @@ -67,8 +65,9 @@ class CeleryService { * * @param $task CeleryTasks the Celery task object * - * @return object the message object + * @return array the message response array * + * @throws CeleryException when no message is found * @throws CeleryTimeoutException when no message is found and more than * $_CELERY_MESSAGE_TIMEOUT milliseconds have passed */ @@ -80,13 +79,19 @@ class CeleryService { // If the message isn't ready yet (Celery hasn't finished the task), // only throw an exception if the message has timed out. - if ($message == FALSE && self::_checkMessageTimeout($task)) { - // If the task times out, mark it as failed. We don't want to remove the - // track reference here in case it was a deletion that failed, for example. - $task->setDbStatus(CELERY_FAILED_STATUS); - $task->save(); - throw new CeleryTimeoutException("Celery task " . $task->getDbName() - . " with ID " . $task->getDbId() . " timed out"); + if ($message == FALSE) { + if (self::_checkMessageTimeout($task)) { + // If the task times out, mark it as failed. We don't want to remove the + // track reference here in case it was a deletion that failed, for example. + $task->setDbStatus(CELERY_FAILED_STATUS)->save(); + throw new CeleryTimeoutException("Celery task " . $task->getDbName() + . " with ID " . $task->getDbId() . " timed out"); + } else { + // The message hasn't timed out, but it's still false, which means it hasn't been + // sent back from Celery yet. + throw new CeleryException("Waiting on Celery task " . $task->getDbName() + . " with ID " . $task->getDbId()); + } } return $message; } @@ -121,7 +126,7 @@ class CeleryService { $message = self::_getTaskMessage($task); self::_processTaskMessage($task, $message); } catch (CeleryTimeoutException $e) { - Logging::info($e->getMessage()); + Logging::warn($e->getMessage()); } catch (Exception $e) { // Because $message->result can be either an object or a string, sometimes // we get a json_decode error and end up here @@ -161,10 +166,11 @@ class CeleryService { * * @return object the task message object * - * @throws CeleryException when the result message for this task no longer exists + * @throws CeleryException when the result message for this task is still pending + * @throws CeleryTimeoutException when the result message for this task no longer exists */ protected static function _getTaskMessage($task) { - $message = self::getAsyncResultMessage($task); + $message = self::getAsyncResultMessage($task); return json_decode($message['body']); } diff --git a/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml b/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml index 594468474..2697a6508 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_soundcloud.phtml @@ -1,19 +1,5 @@