Remove self.entry in VideoTranscoder
[mediagoblin.git] / mediagoblin / processing / __init__.py
index 5a88ddeadf9aa3a01669554c4b727de428f6dfae..a9d5442b40abd7ee8d2289dbd25dc00468b9a378 100644 (file)
@@ -41,7 +41,10 @@ class ProgressCallback(object):
 
     def __call__(self, progress):
         if progress:
-            self.entry.transcoding_progress = progress
+            if 100 - (self.entry.transcoding_progress + progress) < 0.01:
+                self.entry.transcoding_progress = 100
+            else:
+                self.entry.transcoding_progress += progress
             self.entry.save()
 
 
@@ -257,6 +260,12 @@ class ProcessingManager(object):
 
         return processor
 
+    def workflow(self, entry, feed_url, reprocess_action, reprocess_info=None):
+        """
+        Returns the Celery command needed to proceed with media processing
+        """
+        return None
+
 
 def request_from_args(args, which_args):
     """
@@ -309,8 +318,8 @@ def mark_entry_failed(entry_id, exc):
     store extra information that can be useful for users telling them
     why their media failed to process.
 
-    Args:
-     - entry_id: The id of the media entry
+    :param entry_id: The id of the media entry
+    :param exc: An instance of BaseProcessingFail
 
     """
     # Was this a BaseProcessingFail?  In other words, was this a
@@ -325,14 +334,13 @@ def mark_entry_failed(entry_id, exc):
              u'fail_metadata': exc.metadata})
     else:
         _log.warn("No idea what happened here, but it failed: %r", exc)
-        # Looks like no, so just mark it as failed and don't record a
-        # failure_error (we'll assume it wasn't handled) and don't record
-        # metadata (in fact overwrite it if somehow it had previous info
-        # here)
+        # Looks like no, let's record it so that admin could ask us about the
+        # reason
         atomic_update(mgg.database.MediaEntry,
             {'id': entry_id},
             {u'state': u'failed',
-             u'fail_error': None,
+             u'fail_error': u'Unhandled exception: {0}'.format(
+                 six.text_type(exc)),
              u'fail_metadata': {}})
 
 
@@ -378,12 +386,11 @@ def store_public(entry, keyname, local_file, target_name=None,
                   entry.media_files[keyname], target_filepath)
         if delete_if_exists:
             mgg.public_store.delete_file(entry.media_files[keyname])
-
     try:
         mgg.public_store.copy_local_to_storage(local_file, target_filepath)
-    except:
+    except Exception as e:
+        _log.error(u'Exception happened: {0}'.format(e))
         raise PublicStoreFail(keyname=keyname)
-
     # raise an error if the file failed to copy
     if not mgg.public_store.file_exists(target_filepath):
         raise PublicStoreFail(keyname=keyname)
@@ -411,8 +418,11 @@ class BaseProcessingFail(Exception):
         return u"%s:%s" % (
             self.__class__.__module__, self.__class__.__name__)
 
-    def __init__(self, **metadata):
-        self.metadata = metadata or {}
+    def __init__(self, message=None, **metadata):
+        if message is not None:
+            super(BaseProcessingFail, self).__init__(message)
+            metadata['message'] = message
+        self.metadata = metadata
 
 class BadMediaFail(BaseProcessingFail):
     """