Make zencoder and algolia optional packages

If zencoder is not set as ENCODING_BACKEND this can cause issues, but
at least it is possible to run Pillar without the zencoder package
installed. Also, we load the algolia module using the new
SEARCH_BACKEND config setting.
This commit is contained in:
Francesco Siddi 2016-06-26 20:02:41 +02:00
parent 9e6bd9c219
commit ee95abb62a
3 changed files with 8 additions and 7 deletions

View File

@ -4,7 +4,6 @@ import os
import tempfile
from bson import ObjectId
from datetime import datetime
from zencoder import Zencoder
from flask import g
from flask import request
from flask import abort
@ -137,7 +136,7 @@ except KeyError:
raise SystemExit('GCLOUD_PROJECT configuration value is missing')
# Algolia search
if 'ALGOLIA_USER' in app.config:
if app.config['SEARCH_BACKEND'] == 'algolia':
from algoliasearch import algoliasearch
client = algoliasearch.Client(
@ -151,6 +150,7 @@ else:
# Encoding backend
if app.config['ENCODING_BACKEND'] == 'zencoder':
from zencoder import Zencoder
encoding_service_client = Zencoder(app.config['ZENCODER_API_KEY'])
else:
encoding_service_client = None

View File

@ -2,7 +2,6 @@ import logging
import os
from flask import current_app
from zencoder import Zencoder
from application import encoding_service_client
@ -18,13 +17,13 @@ class Encoder:
def job_create(src_file):
"""Create an encoding job. Return the backend used as well as an id.
"""
if not isinstance(encoding_service_client, Zencoder):
log.error('I can only work with Zencoder, not with %r', encoding_service_client)
if current_app.config['ENCODING_BACKEND'] != 'zencoder' or \
encoding_service_client is None:
log.error('I can only work with Zencoder, check the config file.')
return None
if src_file['backend'] != 'gcs':
log.error("Unable to work with storage backend %r", src_file['backend'])
log.error('Unable to work with storage backend %r', src_file['backend'])
return None
# Build the specific GCS input url, assuming the file is stored

View File

@ -51,6 +51,8 @@ ALGOLIA_API_KEY = '-SECRET-'
ALGOLIA_INDEX_USERS = 'dev_Users'
ALGOLIA_INDEX_NODES = 'dev_Nodes'
SEARCH_BACKEND = 'algolia' # algolia, elastic
ZENCODER_API_KEY = '-SECRET-'
ZENCODER_NOTIFICATIONS_SECRET = '-SECRET-'
ZENCODER_NOTIFICATIONS_URL = 'http://zencoderfetcher/'