From ee95abb62a3e575ac76076e9f4c8433fedd88fdf Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Sun, 26 Jun 2016 20:02:41 +0200 Subject: [PATCH] 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. --- pillar/application/__init__.py | 4 ++-- pillar/application/utils/encoding.py | 9 ++++----- pillar/config.py | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pillar/application/__init__.py b/pillar/application/__init__.py index 6cab3070..5d82b8ad 100644 --- a/pillar/application/__init__.py +++ b/pillar/application/__init__.py @@ -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 diff --git a/pillar/application/utils/encoding.py b/pillar/application/utils/encoding.py index e82e1cd4..68688273 100644 --- a/pillar/application/utils/encoding.py +++ b/pillar/application/utils/encoding.py @@ -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 diff --git a/pillar/config.py b/pillar/config.py index 67eb3969..08c0f148 100644 --- a/pillar/config.py +++ b/pillar/config.py @@ -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/'