Lots of fixes to do this.
- setup_celery_from_config no longer responsible for checking
'celery_setup_elsewhere'; that's the app's job. (This was a problem
because more than the app was relying on using this function)
- Allow us to specifically set the config file we're setting up
celery from with setup_self
- Set up celery_always_eager. This is something we strongly want
while doing tests.
- Instead of setting up the app in the get_test_app method, let's set
that up simply by importing from_tests, which should itself up via
from_celery being the environment variable being set.
- set_environ: if set, this will CELERY_CONFIG_MODULE to the
settings_module
"""
- if app_config.get('celery_setup_elsewhere') == True:
- # Don't setup celery based on our config file.
- return
-
if global_config.has_key('celery'):
celery_conf = global_config['celery']
else:
OUR_MODULENAME = __name__
-def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME):
+def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME,
+ default_conf_file='mediagoblin.ini'):
"""
Transform this module into a celery config module by reading the
mediagoblin config file. Set the environment variable
"""
if check_environ_for_conf:
mgoblin_conf_file = os.path.abspath(
- os.environ.get('MEDIAGOBLIN_CONFIG', 'mediagoblin.ini'))
+ os.environ.get('MEDIAGOBLIN_CONFIG', default_conf_file))
else:
- mgoblin_conf_file = 'mediagoblin.ini'
+ mgoblin_conf_file = default_conf_file
if not os.path.exists(mgoblin_conf_file):
raise IOError(
# this is the module that gets set up.
os.environ['CELERY_CONFIG_MODULE'] = module_name
app.MediaGoblinApp(mgoblin_conf_file, setup_celery=False)
+
setup_celery_from_config(
mg_globals.app_config, mg_globals.global_config,
settings_module=module_name,
import os
+from mediagoblin.tests.tools import TEST_APP_CONFIG
from mediagoblin.celery_setup.from_celery import setup_self
OUR_MODULENAME = __name__
+CELERY_SETUP = False
if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
- setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME)
+ setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME,
+ default_conf_file=TEST_APP_CONFIG)
+ CELERY_SETUP = True
email_debug_mode = true
db_name = __mediagoblin_tests__
-# Celery shouldn't be set up by the paste app factory as it's set up
-# elsewhere
+# Celery shouldn't be set up by the application as it's setup via
+# mediagoblin.celery_setup.from_celery
celery_setup_elsewhere = true
+
+[celery]
+celery_always_eager = true
from paste.deploy import loadapp
from webtest import TestApp
-from mediagoblin import util, mg_globals
+from mediagoblin import util
from mediagoblin.config import read_mediagoblin_config
-from mediagoblin.celery_setup import setup_celery_from_config
from mediagoblin.decorators import _make_safe
from mediagoblin.db.open import setup_connection_and_db_from_config
TEST_USER_DEV = pkg_resources.resource_filename(
'mediagoblin.tests', 'test_user_dev')
MGOBLIN_APP = None
-CELERY_SETUP = False
USER_DEV_DIRECTORIES_TO_SETUP = [
'media/public', 'media/queue',
def get_test_app(dump_old_app=True):
suicide_if_bad_celery_environ()
+ # Leave this imported as it sets up celery.
+ from mediagoblin.celery_setup import from_tests
+
global MGOBLIN_APP
- global CELERY_SETUP
# Just return the old app if that exists and it's okay to set up
# and return
app = TestApp(test_app)
MGOBLIN_APP = app
- # setup celery
- if not CELERY_SETUP:
- setup_celery_from_config(
- mg_globals.app_config, mg_globals.global_config,
- set_environ=True)
- CELERY_SETUP = True
-
return app