Better handling of Zencoder error notifications.
This commit is contained in:
parent
5ae98507e3
commit
89ca0516a9
@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ def size_descriptor(width, height):
|
|||||||
1280: '720p',
|
1280: '720p',
|
||||||
1920: '1080p',
|
1920: '1080p',
|
||||||
2048: '2k',
|
2048: '2k',
|
||||||
|
3840: 'UHD',
|
||||||
4096: '4k',
|
4096: '4k',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,18 +106,13 @@ def zencoder_notifications():
|
|||||||
file_doc['processing']['status'] = job_state
|
file_doc['processing']['status'] = job_state
|
||||||
|
|
||||||
if job_state == 'failed':
|
if job_state == 'failed':
|
||||||
log.warning('Zencoder job %i for file %s failed.', zencoder_job_id, file_id)
|
log.warning('Zencoder job %s for file %s failed: %s', zencoder_job_id, file_id,
|
||||||
# Log what Zencoder told us went wrong.
|
json.dumps(data, sort_keys=True, indent=4))
|
||||||
for output in data['outputs']:
|
|
||||||
if not any('error' in key for key in output):
|
|
||||||
continue
|
|
||||||
log.warning('Errors for output %s:', output['url'])
|
|
||||||
for key in output:
|
|
||||||
if 'error' in key:
|
|
||||||
log.info(' %s: %s', key, output[key])
|
|
||||||
|
|
||||||
file_doc['status'] = 'failed'
|
file_doc['status'] = 'failed'
|
||||||
current_app.put_internal('files', file_doc, _id=file_id)
|
current_app.put_internal('files', file_doc, _id=file_id)
|
||||||
|
|
||||||
|
# This is 'okay' because we handled the Zencoder notification properly.
|
||||||
return "You failed, but that's okay.", 200
|
return "You failed, but that's okay.", 200
|
||||||
|
|
||||||
log.info('Zencoder job %s for file %s completed with status %s.', zencoder_job_id, file_id,
|
log.info('Zencoder job %s for file %s completed with status %s.', zencoder_job_id, file_id,
|
||||||
|
@ -36,7 +36,7 @@ class ZencoderNotificationTest(AbstractPillarTest):
|
|||||||
expected_status=401)
|
expected_status=401)
|
||||||
|
|
||||||
def test_good_secret_existing_file(self):
|
def test_good_secret_existing_file(self):
|
||||||
self.ensure_file_exists(file_overrides={
|
file_id, _ = self.ensure_file_exists(file_overrides={
|
||||||
'processing': {'backend': 'zencoder',
|
'processing': {'backend': 'zencoder',
|
||||||
'job_id': 'koro-007',
|
'job_id': 'koro-007',
|
||||||
'status': 'processing'}
|
'status': 'processing'}
|
||||||
@ -44,7 +44,7 @@ class ZencoderNotificationTest(AbstractPillarTest):
|
|||||||
|
|
||||||
self.post('/api/encoding/zencoder/notifications',
|
self.post('/api/encoding/zencoder/notifications',
|
||||||
json={'job': {'id': 'koro-007',
|
json={'job': {'id': 'koro-007',
|
||||||
'state': 'done'},
|
'state': 'finished'},
|
||||||
'outputs': [{
|
'outputs': [{
|
||||||
'format': 'jpg',
|
'format': 'jpg',
|
||||||
'height': 1080,
|
'height': 1080,
|
||||||
@ -58,4 +58,34 @@ class ZencoderNotificationTest(AbstractPillarTest):
|
|||||||
headers={'X-Zencoder-Notification-Secret': self.secret},
|
headers={'X-Zencoder-Notification-Secret': self.secret},
|
||||||
expected_status=204)
|
expected_status=204)
|
||||||
|
|
||||||
# TODO: check that the file in MongoDB is actually updated properly.
|
db_file = self.app.db('files').find_one(file_id)
|
||||||
|
self.assertEqual('complete', db_file['status'])
|
||||||
|
self.assertEqual('finished', db_file['processing']['status'])
|
||||||
|
|
||||||
|
def test_failed_job(self):
|
||||||
|
file_id, _ = self.ensure_file_exists(file_overrides={
|
||||||
|
'processing': {'backend': 'zencoder',
|
||||||
|
'job_id': 'koro-007',
|
||||||
|
'status': 'processing'}
|
||||||
|
})
|
||||||
|
|
||||||
|
self.post('/api/encoding/zencoder/notifications',
|
||||||
|
json={'job': {'id': 'koro-007',
|
||||||
|
'state': 'failed'},
|
||||||
|
'outputs': [{
|
||||||
|
'format': 'jpg',
|
||||||
|
'height': 1080,
|
||||||
|
'width': 2048,
|
||||||
|
'file_size_in_bytes': 15,
|
||||||
|
'md5_checksum': None,
|
||||||
|
'error': 'Lama support malfunctioning',
|
||||||
|
'url': 'http://example.com/file.mp4',
|
||||||
|
}],
|
||||||
|
'input': {
|
||||||
|
'duration_in_ms': 5000,
|
||||||
|
}},
|
||||||
|
headers={'X-Zencoder-Notification-Secret': self.secret})
|
||||||
|
|
||||||
|
db_file = self.app.db('files').find_one(file_id)
|
||||||
|
self.assertEqual('failed', db_file['status'])
|
||||||
|
self.assertEqual('failed', db_file['processing']['status'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user