More small TaskManager and auto-ingest fixes

This commit is contained in:
Duncan Sommerville 2015-10-29 18:26:20 -04:00
parent e3feb17f0c
commit d08e19a93a
2 changed files with 20 additions and 16 deletions

View File

@ -30,7 +30,12 @@ class PodcastManager {
$service = new Application_Service_PodcastEpisodeService(); $service = new Application_Service_PodcastEpisodeService();
foreach ($autoIngestPodcasts as $podcast) { foreach ($autoIngestPodcasts as $podcast) {
$episodes = static::_findUningestedEpisodes($podcast, $service); $episodes = static::_findUningestedEpisodes($podcast, $service);
$podcast->setDbAutoIngestTimestamp(gmdate('r'))->save(); // Since episodes don't have to be uploaded with a time (H:i:s) component,
// store the timestamp of the most recent (first pushed to the array) episode
// that we're ingesting.
// Note that this folds to the failure case (Celery task timeout/download failure)
// but will at least continue to ingest new episodes.
$podcast->setDbAutoIngestTimestamp(gmdate('r', strtotime($episodes[0]->getDbPublicationDate())))->save();
$service->downloadEpisodes($episodes); $service->downloadEpisodes($episodes);
} }

View File

@ -55,23 +55,22 @@ class PageLayoutInitPlugin extends Zend_Controller_Plugin_Abstract
$this->_initViewHelpers(); $this->_initViewHelpers();
} }
// Piggyback the TaskManager onto API calls // Skip upgrades and task management when running unit tests
if ($controller == "api") {
$this->_initTasks();
}
}
/**
* If we're not running unit tests, run the TaskManager tasks on each request
*/
protected function _initTasks() {
/* We need to wrap this here so that we aren't checking when we're running the unit test suite
*/
if (getenv("AIRTIME_UNIT_TEST") != 1) { if (getenv("AIRTIME_UNIT_TEST") != 1) {
$taskManager = TaskManager::getInstance(); $taskManager = TaskManager::getInstance();
$taskManager->runTask(TaskFactory::UPGRADE); // Run the upgrade on each request (if it needs to be run)
//This will do the upgrade too if it's needed... // Run the upgrade on each request (if it needs to be run)
$taskManager->runTasks(); // We can't afford to wait 7 minutes to run an upgrade: users could
// have several minutes of database errors while waiting for a
// schema change upgrade to happen after a deployment
$taskManager->runTask(TaskFactory::UPGRADE);
// Piggyback the TaskManager onto API calls. This provides guaranteed consistency
// (there is at least one API call made from pypo to Airtime every 7 minutes) and
// greatly reduces the chances of lock contention on cc_pref while the TaskManager runs
if ($controller == "api") {
$taskManager->runTasks();
}
} }
} }