HTTP callback fixes
authorJoar Wandborg <git@wandborg.com>
Mon, 24 Sep 2012 23:06:25 +0000 (01:06 +0200)
committerJoar Wandborg <git@wandborg.com>
Wed, 26 Sep 2012 21:53:51 +0000 (23:53 +0200)
- Added HTTPError catching around the callback request, to not mark the
  entry as failed, just log the exception.
- Fixed bug where I forgot to actually fetch the entry before passing it
  to json_processing_callback.
- Changed __main__ migration #6 to create the ProcessingMetaData table
  as it is currently, to prevent possible breakage if a siteadmin
  is lagging behind with his db migrations and more than one migration
  wants to fix stuff with the ProcessingMetaData table.

mediagoblin/db/sql/migrations.py
mediagoblin/processing/task.py
mediagoblin/tools/processing.py

index 416c076b2ac7a45c58634765b9c640ba8a038120..1d822cd97bc05a813264093afc99634a82858021 100644 (file)
@@ -106,5 +106,13 @@ def add_mediaentry_collected(db_conn):
 
 @RegisterMigration(6, MIGRATIONS)
 def create_processing_metadata_table(db):
-    ProcessingMetaData.__table__.create(db.bind)
+    metadata = MetaData(bind=db.bind)
+
+    metadata_table = Table('core__processing_metadata', metadata,
+            Column('id', Integer, primary_key=True),
+            Column('media_entry_id', Integer, ForeignKey(MediaEntry.id),
+                nullable=False, index=True),
+            Column('callback_url', Unicode))
+
+    metadata_table.create()
     db.commit()
index 7f4b842998f8d65659ea0f256e76cc62025e67c5..187b893dc47c9f2ccc3e081962dc544ea13be2d8 100644 (file)
@@ -96,5 +96,5 @@ class ProcessMedia(Task):
         entry_id = args[0]
         mark_entry_failed(entry_id, exc)
 
-        entry = mgg.database.MediaEntry.query.filter_by(id=entry_id)
+        entry = mgg.database.MediaEntry.query.filter_by(id=entry_id).first()
         json_processing_callback(entry)
index 41a0a5fae3e834979de390e111b72afd64c2cbc6..5840c7e0a537ad944fc05a3ef40c179f170d1213 100644 (file)
@@ -16,8 +16,9 @@
 
 import logging
 import json
+import traceback
 
-from urllib2 import urlopen, Request
+from urllib2 import urlopen, Request, HTTPError
 from urllib import urlencode
 
 _log = logging.getLogger(__name__)
@@ -67,7 +68,13 @@ def json_processing_callback(entry):
             headers=headers,
             data_parser=json.dumps)
 
-    urlopen(request)
-    _log.debug('Processing callback for {0} sent'.format(entry))
+    try:
+        urlopen(request)
+        _log.debug('Processing callback for {0} sent'.format(entry))
 
-    return True
+        return True
+    except HTTPError:
+        _log.error('Failed to send callback: {0}'.format(
+            traceback.format_exc()))
+
+        return False