From 071de55329e14cba0e29fab28fdbe6eefe360000 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 11 Nov 2015 19:26:51 -0500 Subject: [PATCH] Add some additional error handling and prevent disabled buttons from being triggered --- .../services/PodcastEpisodeService.php | 30 +++++++++++-------- .../public/js/airtime/library/library.js | 2 ++ .../public/js/airtime/widgets/table.js | 5 +++- .../airtime-celery/airtime-celery/tasks.py | 2 +- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/services/PodcastEpisodeService.php b/airtime_mvc/application/services/PodcastEpisodeService.php index c9a11e9b2..e2e2aed1c 100644 --- a/airtime_mvc/application/services/PodcastEpisodeService.php +++ b/airtime_mvc/application/services/PodcastEpisodeService.php @@ -161,22 +161,26 @@ class Application_Service_PodcastEpisodeService extends Application_Service_Thir */ public function updateTrackReference($task, $episodeId, $episode, $status) { $ref = parent::updateTrackReference($task, $episodeId, $episode, $status); + $dbEpisode = PodcastEpisodesQuery::create()->findOneByDbId($episode->episodeid); - $dbEpisode = PodcastEpisodesQuery::create() - ->findOneByDbId($episode->episodeid); + try { + // If the placeholder for the episode is somehow removed, return with a warning + if (!$dbEpisode) { + Logging::warn("Celery task $task episode $episode->episodeid unsuccessful: episode placeholder removed"); + return $ref; + } - // If the placeholder for the episode is somehow removed, return with a warning - if (!$dbEpisode) { - Logging::warn("Celery task $task episode $episode->episodeid unsuccessful: episode placeholder removed"); - return $ref; - } - - // Even if the task itself succeeds, the download could have failed, so check the status - if ($status == CELERY_SUCCESS_STATUS && $episode->status == 1) { - $dbEpisode->setDbFileId($episode->fileid)->save(); - } else { - Logging::warn("Celery task $task episode $episode->episodeid unsuccessful with message $episode->error"); + // Even if the task itself succeeds, the download could have failed, so check the status + if ($status == CELERY_SUCCESS_STATUS && $episode->status == 1) { + $dbEpisode->setDbFileId($episode->fileid)->save(); + } else { + Logging::warn("Celery task $task episode $episode->episodeid unsuccessful with message $episode->error"); + $dbEpisode->delete(); + } + } catch (Exception $e) { $dbEpisode->delete(); + Logging::warn("Catastrophic failure updating from task $task, recovering by deleting episode row.\n + This can occur if the episode's corresponding CcFile is deleted before being processed."); } return $ref; diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 3539307aa..6efdab6d9 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -1443,6 +1443,7 @@ var AIRTIME = (function(AIRTIME) { var selected = this.getSelectedRows(), isValid = true; if (selected.length == 0) return false; $.each(selected, function () { + if (this.ingested < 0) isValid = false; var isImported = !$.isEmptyObject(this.file); if ((!shouldBeImported && isImported) || (shouldBeImported && !isImported)) { isValid = false; @@ -1483,6 +1484,7 @@ var AIRTIME = (function(AIRTIME) { click: function () { var data = [], episodes = mod.podcastEpisodeTableWidget.getSelectedRows(); $.each(episodes, function () { + if (this.file.ftype === "") { this.file.ftype = "audioclip"; } data.push({id: this.file.id, type: this.file.ftype}); }); mod.fnDeleteItems(data); diff --git a/airtime_mvc/public/js/airtime/widgets/table.js b/airtime_mvc/public/js/airtime/widgets/table.js index a9ff5ee3e..0ca0dcf2c 100644 --- a/airtime_mvc/public/js/airtime/widgets/table.js +++ b/airtime_mvc/public/js/airtime/widgets/table.js @@ -210,7 +210,10 @@ var AIRTIME = (function(AIRTIME) { btn.element = buttonElement; //Save this guy in case you need it later. //Bind event handlers to each button $.each(btn.eventHandlers, function(eventName, eventCallback) { - $(buttonElement).on(eventName, eventCallback); + $(buttonElement).on(eventName, function () { + if ($(buttonElement).find("button").is(':disabled')) { return; } + eventCallback(); + }); }); }); diff --git a/python_apps/airtime-celery/airtime-celery/tasks.py b/python_apps/airtime-celery/airtime-celery/tasks.py index 0f6841526..68a7e7dd3 100644 --- a/python_apps/airtime-celery/airtime-celery/tasks.py +++ b/python_apps/airtime-celery/airtime-celery/tasks.py @@ -125,7 +125,7 @@ def soundcloud_delete(token, track_id): @celery.task(name='podcast-download', acks_late=True) def podcast_download(id, url, callback_url, api_key): """ - Download a batch of podcast episodes + Download a podcast episode :param id: episode unique ID :param url: download url for the episode