Sweep pending podcast episodes after an hour; css tweaks to My Podcast page
This commit is contained in:
parent
0efaf836b0
commit
e4027c1e1f
|
@ -133,17 +133,23 @@ class Application_Service_MediaService
|
||||||
->filterByDbImportStatus(CcFiles::IMPORT_STATUS_PENDING)
|
->filterByDbImportStatus(CcFiles::IMPORT_STATUS_PENDING)
|
||||||
->filterByDbUtime($oneHourAgo, Criteria::LESS_EQUAL)
|
->filterByDbUtime($oneHourAgo, Criteria::LESS_EQUAL)
|
||||||
->find();
|
->find();
|
||||||
return !empty(self::$_pendingFiles);
|
$pendingEpisodes = Application_Service_PodcastEpisodeService::getStuckPendingImports();
|
||||||
|
return !empty(self::$_pendingFiles) && !empty($pendingEpisodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up stuck imports by changing their import status to Failed
|
* Clean up stuck imports by changing their import status to Failed
|
||||||
*/
|
*/
|
||||||
public static function clearStuckPendingImports() {
|
public static function clearStuckPendingImports() {
|
||||||
foreach(self::$_pendingFiles as $file) {
|
$pendingEpisodes = Application_Service_PodcastEpisodeService::getStuckPendingImports();
|
||||||
|
foreach (self::$_pendingFiles as $file) {
|
||||||
/** @var $file CcFiles */
|
/** @var $file CcFiles */
|
||||||
$file->setDbImportStatus(CcFiles::IMPORT_STATUS_FAILED)->save();
|
$file->setDbImportStatus(CcFiles::IMPORT_STATUS_FAILED)->save();
|
||||||
}
|
}
|
||||||
|
foreach ($pendingEpisodes as $episode) {
|
||||||
|
/** @var $episode PodcastEpisodes */
|
||||||
|
$episode->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
|
|
||||||
const DOWNLOAD = 'download';
|
const DOWNLOAD = 'download';
|
||||||
|
|
||||||
|
const PENDING_EPISODE_TIMEOUT_SECONDS = 3600;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string service name to store in ThirdPartyTrackReferences database
|
* @var string service name to store in ThirdPartyTrackReferences database
|
||||||
*/
|
*/
|
||||||
|
@ -143,7 +145,11 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
'callback_url' => Application_Common_HTTPHelper::getStationUrl() . '/rest/media',
|
'callback_url' => Application_Common_HTTPHelper::getStationUrl() . '/rest/media',
|
||||||
'api_key' => $apiKey = $CC_CONFIG["apiKey"][0],
|
'api_key' => $apiKey = $CC_CONFIG["apiKey"][0],
|
||||||
);
|
);
|
||||||
$this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
|
$task = $this->_executeTask(static::$_CELERY_TASKS[self::DOWNLOAD], $data);
|
||||||
|
// Get the created ThirdPartyTaskReference and set the episode ID so
|
||||||
|
// we can remove the placeholder if the import ends up stuck in a pending state
|
||||||
|
$ref = ThirdPartyTrackReferencesQuery::create()->findPk($task->getDbTrackReference());
|
||||||
|
$ref->setDbForeignId($id)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,6 +167,7 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
*/
|
*/
|
||||||
public function updateTrackReference($task, $episodeId, $episode, $status) {
|
public function updateTrackReference($task, $episodeId, $episode, $status) {
|
||||||
$ref = parent::updateTrackReference($task, $episodeId, $episode, $status);
|
$ref = parent::updateTrackReference($task, $episodeId, $episode, $status);
|
||||||
|
$ref->setDbForeignId($episode->episodeid)->save();
|
||||||
$dbEpisode = PodcastEpisodesQuery::create()->findOneByDbId($episode->episodeid);
|
$dbEpisode = PodcastEpisodesQuery::create()->findOneByDbId($episode->episodeid);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -231,6 +238,32 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir
|
||||||
return (int) $stationPodcast->hasEpisodeForFile($fileId);
|
return (int) $stationPodcast->hasEpisodeForFile($fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find any episode placeholders that have been stuck pending (empty file ID) for over an hour
|
||||||
|
*
|
||||||
|
* @return array the episode imports stuck in pending
|
||||||
|
*/
|
||||||
|
public static function getStuckPendingImports() {
|
||||||
|
$oneHourAgo = gmdate(DEFAULT_TIMESTAMP_FORMAT, (microtime(true) - self::PENDING_EPISODE_TIMEOUT_SECONDS));
|
||||||
|
$episodes = PodcastEpisodesQuery::create()
|
||||||
|
->filterByDbFileId()
|
||||||
|
->find();
|
||||||
|
$stuckImports = array();
|
||||||
|
foreach ($episodes as $episode) {
|
||||||
|
$ref = ThirdPartyTrackReferencesQuery::create()
|
||||||
|
->findOneByDbForeignId(strval($episode->getDbId()));
|
||||||
|
if (!empty($ref)) {
|
||||||
|
$task = CeleryTasksQuery::create()
|
||||||
|
->filterByDbDispatchTime($oneHourAgo, Criteria::LESS_EQUAL)
|
||||||
|
->findOneByDbTrackReference($ref->getDbId());
|
||||||
|
if (!empty($task)) {
|
||||||
|
array_push($stuckImports, $episode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $stuckImports;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $episodeId
|
* @param $episodeId
|
||||||
* @return array
|
* @return array
|
||||||
|
|
|
@ -20,15 +20,20 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
|
||||||
* @param string $taskName the name of the celery task to execute
|
* @param string $taskName the name of the celery task to execute
|
||||||
* @param array $data the data array to send as task parameters
|
* @param array $data the data array to send as task parameters
|
||||||
* @param int $fileId the unique identifier for the file involved in the task
|
* @param int $fileId the unique identifier for the file involved in the task
|
||||||
|
*
|
||||||
|
* @return CeleryTasks the created task
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function _executeTask($taskName, $data, $fileId = null) {
|
protected function _executeTask($taskName, $data, $fileId = null) {
|
||||||
try {
|
try {
|
||||||
$brokerTaskId = CeleryManager::sendCeleryMessage($taskName,
|
$brokerTaskId = CeleryManager::sendCeleryMessage($taskName,
|
||||||
static::$_CELERY_EXCHANGE_NAME,
|
static::$_CELERY_EXCHANGE_NAME,
|
||||||
$data);
|
$data);
|
||||||
$this->_createTaskReference($fileId, $brokerTaskId, $taskName);
|
return $this->_createTaskReference($fileId, $brokerTaskId, $taskName);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logging::info("Invalid request: " . $e->getMessage());
|
Logging::error("Invalid request: " . $e->getMessage());
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +46,8 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
|
||||||
* receive completed task messages
|
* receive completed task messages
|
||||||
* @param $taskName string broker task name
|
* @param $taskName string broker task name
|
||||||
*
|
*
|
||||||
|
* @return CeleryTasks the created task
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws PropelException
|
* @throws PropelException
|
||||||
*/
|
*/
|
||||||
|
@ -54,6 +61,7 @@ abstract class Application_Service_ThirdPartyCeleryService extends Application_S
|
||||||
$task->setDbStatus(CELERY_PENDING_STATUS);
|
$task->setDbStatus(CELERY_PENDING_STATUS);
|
||||||
$task->setDbTrackReference($trackReferenceId);
|
$task->setDbTrackReference($trackReferenceId);
|
||||||
$task->save();
|
$task->save();
|
||||||
|
return $task;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,12 +30,10 @@ abstract class Application_Service_ThirdPartyService {
|
||||||
public function createTrackReference($fileId) {
|
public function createTrackReference($fileId) {
|
||||||
// First, check if the track already has an entry in the database
|
// First, check if the track already has an entry in the database
|
||||||
// If the file ID given is null, create a new reference
|
// If the file ID given is null, create a new reference
|
||||||
$ref = is_null($fileId) ? null : ThirdPartyTrackReferencesQuery::create()
|
$ref = is_null($fileId) ? new ThirdPartyTrackReferences()
|
||||||
->filterByDbService(static::$_SERVICE_NAME)
|
: ThirdPartyTrackReferencesQuery::create()
|
||||||
->findOneByDbFileId($fileId);
|
->filterByDbService(static::$_SERVICE_NAME)
|
||||||
if (is_null($ref)) {
|
->findOneByDbFileId($fileId);
|
||||||
$ref = new ThirdPartyTrackReferences();
|
|
||||||
}
|
|
||||||
$ref->setDbService(static::$_SERVICE_NAME);
|
$ref->setDbService(static::$_SERVICE_NAME);
|
||||||
$ref->setDbFileId($fileId);
|
$ref->setDbFileId($fileId);
|
||||||
$ref->save();
|
$ref->save();
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="angular_wrapper" ng-controller="Podcast">
|
<div class="angular_wrapper" ng-controller="Podcast">
|
||||||
<div class="inner_editor_title">
|
<div class="inner_editor_title">
|
||||||
<h2>
|
<h2>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div id="station_podcast">
|
<div id="station_podcast">
|
||||||
<div class="angular_wrapper" ng-controller="StationPodcast">
|
<div class="angular_wrapper" ng-controller="StationPodcast">
|
||||||
<div class="station_podcast_wrapper">
|
<div class="station_podcast_wrapper content-pane">
|
||||||
<div class="inner_editor_title">
|
<div class="inner_editor_title">
|
||||||
<h2>
|
<h2>
|
||||||
<span class="title_obj_name"><?php echo _("My Podcast") ?></span>
|
<span class="title_obj_name"><?php echo _("My Podcast") ?></span>
|
||||||
|
|
|
@ -739,7 +739,11 @@ div.ColVis_collectionBackground {
|
||||||
|
|
||||||
.fg-toolbar .btn-toolbar {
|
.fg-toolbar .btn-toolbar {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 6px 6px 5px;
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fg-toolbar .btn-toolbar .ColVis_MasterButton {
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
/* ~~~~~~~~~~~~~~~~ */
|
/* ~~~~~~~~~~~~~~~~ */
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.station_podcast_wrapper {
|
.station_podcast_wrapper {
|
||||||
padding-right: 4px;
|
padding: 8px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue