aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/processing
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2013-08-11 14:34:45 -0500
committerRodney Ewing <ewing.rj@gmail.com>2013-08-16 15:30:16 -0700
commit77ea4c9bd1e8372fb7206596ca5125738033ced5 (patch)
treecfef03b64d9c86f65d75375eda36175aab6b681c /mediagoblin/processing
parentd1e9913b71a6f3b7bb41f5eee1051093b92fcd8a (diff)
downloadmediagoblin-77ea4c9bd1e8372fb7206596ca5125738033ced5.tar.lz
mediagoblin-77ea4c9bd1e8372fb7206596ca5125738033ced5.tar.xz
mediagoblin-77ea4c9bd1e8372fb7206596ca5125738033ced5.zip
Updating to the point where we can allllmost run with the new reprocessing code
This commit sponsored by Odin Hørthe Omdal. Thank you!
Diffstat (limited to 'mediagoblin/processing')
-rw-r--r--mediagoblin/processing/__init__.py40
-rw-r--r--mediagoblin/processing/task.py26
2 files changed, 46 insertions, 20 deletions
diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py
index 1c8f7202..b668baa7 100644
--- a/mediagoblin/processing/__init__.py
+++ b/mediagoblin/processing/__init__.py
@@ -18,9 +18,10 @@ from collections import OrderedDict
import logging
import os
-from mediagoblin.db.util import atomic_update
from mediagoblin import mg_globals as mgg
-
+from mediagoblin.db.util import atomic_update
+from mediagoblin.db.models import MediaEntry
+from mediagoblin.tools.pluginapi import hook_handle
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
_log = logging.getLogger(__name__)
@@ -208,7 +209,7 @@ class ProcessingManager(object):
return processor
- def process(self, entry, directive, request):
+ def process_from_args(self, entry, reprocess_command, request):
"""
Process a media entry.
"""
@@ -226,6 +227,39 @@ def request_from_args(args, which_args):
return request
+class MediaEntryNotFound(Exception): pass
+
+
+def get_manager_for_type(media_type):
+ """
+ Get the appropriate media manager for this type
+ """
+ manager_class = hook_handle(('reprocess_manager', media_type))
+ manager = manager_class()
+
+ return manager
+
+
+def get_entry_and_manager(media_id):
+ """
+ Get a MediaEntry, its media type, and its manager all in one go.
+
+ Returns a tuple of: `(entry, media_type, media_manager)`
+ """
+ entry = MediaEntry.query.filter_by(id=media_id).first()
+ if entry is None:
+ raise MediaEntryNotFound("Can't find media with id '%s'" % media_id)
+
+ manager = get_manager_for_type(entry.media_type)
+
+ return entry, manager
+
+
+################################################
+# TODO: This ProcessingState is OUTDATED,
+# and needs to be refactored into other tools!
+################################################
+
class ProcessingState(object):
"""
The first and only argument to the "processor" of a media type
diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py
index 36ee31fd..240be4e5 100644
--- a/mediagoblin/processing/task.py
+++ b/mediagoblin/processing/task.py
@@ -21,9 +21,9 @@ import urllib2
from celery import registry, task
from mediagoblin import mg_globals as mgg
-from mediagoblin.db.models import MediaEntry
-from . import mark_entry_failed, BaseProcessingFail, ProcessingState
+from . import mark_entry_failed, BaseProcessingFail
from mediagoblin.tools.processing import json_processing_callback
+from mediagoblin.processing import get_entry_and_manager
_log = logging.getLogger(__name__)
logging.basicConfig()
@@ -68,7 +68,7 @@ class ProcessMedia(task.Task):
"""
Pass this entry off for processing.
"""
- def run(self, media_id, feed_url, reprocess_info=None):
+ def run(self, media_id, feed_url, reprocess_action, reprocess_info=None):
"""
Pass the media entry off to the appropriate processing function
(for now just process_image...)
@@ -78,28 +78,20 @@ class ProcessMedia(task.Task):
:param reprocess: A dict containing all of the necessary reprocessing
info for the media_type.
"""
- entry = MediaEntry.query.get(media_id)
+ reprocess_info = reprocess_info or {}
+ entry, manager = get_entry_and_manager(media_id)
# Try to process, and handle expected errors.
try:
+ processor_class = manager.get_processor(reprocess_action, entry)
+
entry.state = u'processing'
entry.save()
_log.debug('Processing {0}'.format(entry))
- proc_state = ProcessingState(entry)
- with mgg.workbench_manager.create() as workbench:
-
- proc_state.set_workbench(workbench)
- processor = entry.media_manager.processor(proc_state)
-
- # If we have reprocess_info, let's reprocess
- if reprocess_info:
- processor.reprocess(reprocess_info)
-
- # Run initial processing
- else:
- processor.initial_processing()
+ with processor_class(manager, entry) as processor:
+ processor.process(**reprocess_info)
# We set the state to processed and save the entry here so there's
# no need to save at the end of the processing stage, probably ;)