Updating celery_setup.from_celery to use new config loading / app init
- The code for this is significantly simpler now. The app sets up everything but celery, and from_celery finishes the job. - There's no more specifying the mediagoblin section in the file, which doesn't make sense anymore and was already confusing.
This commit is contained in:
parent
52f20ff337
commit
924c586b72
@ -16,14 +16,8 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from paste.deploy.loadwsgi import NicerConfigParser
|
from mediagoblin import app, mg_globals
|
||||||
from paste.deploy.converters import asbool
|
|
||||||
|
|
||||||
from mediagoblin import storage
|
|
||||||
from mediagoblin.db.open import setup_connection_and_db_from_config
|
|
||||||
from mediagoblin.celery_setup import setup_celery_from_config
|
from mediagoblin.celery_setup import setup_celery_from_config
|
||||||
from mediagoblin.mg_globals import setup_globals
|
|
||||||
from mediagoblin.workbench import WorkbenchManager, DEFAULT_WORKBENCH_DIR
|
|
||||||
|
|
||||||
|
|
||||||
OUR_MODULENAME = __name__
|
OUR_MODULENAME = __name__
|
||||||
@ -33,64 +27,28 @@ def setup_self():
|
|||||||
"""
|
"""
|
||||||
Transform this module into a celery config module by reading the
|
Transform this module into a celery config module by reading the
|
||||||
mediagoblin config file. Set the environment variable
|
mediagoblin config file. Set the environment variable
|
||||||
MEDIAGOBLIN_CONFIG to specify where this config file is at and
|
MEDIAGOBLIN_CONFIG to specify where this config file is.
|
||||||
what section it uses.
|
|
||||||
|
|
||||||
By default it defaults to 'mediagoblin.ini:app:mediagoblin'.
|
By default it defaults to 'mediagoblin.ini'.
|
||||||
|
|
||||||
The first colon ":" is a delimiter between the filename and the
|
Note that if celery_setup_elsewhere is set in your config file,
|
||||||
config section, so in this case the filename is 'mediagoblin.ini'
|
this simply won't work.
|
||||||
and the section where mediagoblin is defined is 'app:mediagoblin'.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
- 'setup_globals_func': this is for testing purposes only. Don't
|
|
||||||
set this!
|
|
||||||
"""
|
"""
|
||||||
mgoblin_conf_file, mgoblin_section = os.environ.get(
|
mgoblin_conf_file = os.path.abspath(
|
||||||
'MEDIAGOBLIN_CONFIG', 'mediagoblin.ini:app:mediagoblin').split(':', 1)
|
os.environ.get('MEDIAGOBLIN_CONFIG', 'mediagoblin.ini'))
|
||||||
if not os.path.exists(mgoblin_conf_file):
|
if not os.path.exists(mgoblin_conf_file):
|
||||||
raise IOError(
|
raise IOError(
|
||||||
"MEDIAGOBLIN_CONFIG not set or file does not exist")
|
"MEDIAGOBLIN_CONFIG not set or file does not exist")
|
||||||
|
|
||||||
parser = NicerConfigParser(mgoblin_conf_file)
|
# By setting the environment variable here we should ensure that
|
||||||
parser.read(mgoblin_conf_file)
|
# this is the module that gets set up.
|
||||||
parser._defaults.setdefault(
|
os.environ['CELERY_CONFIG_MODULE'] = OUR_MODULENAME
|
||||||
'here', os.path.dirname(os.path.abspath(mgoblin_conf_file)))
|
app.MediaGoblinApp(mgoblin_conf_file, setup_celery=False)
|
||||||
parser._defaults.setdefault(
|
|
||||||
'__file__', os.path.abspath(mgoblin_conf_file))
|
|
||||||
|
|
||||||
mgoblin_section = dict(parser.items(mgoblin_section))
|
|
||||||
mgoblin_conf = dict(
|
|
||||||
[(section_name, dict(parser.items(section_name)))
|
|
||||||
for section_name in parser.sections()])
|
|
||||||
setup_celery_from_config(
|
setup_celery_from_config(
|
||||||
mgoblin_section, mgoblin_conf,
|
mg_globals.app_config, mg_globals.global_config,
|
||||||
settings_module=OUR_MODULENAME,
|
settings_module=OUR_MODULENAME,
|
||||||
set_environ=False)
|
set_environ=False)
|
||||||
|
|
||||||
connection, db = setup_connection_and_db_from_config(mgoblin_section)
|
|
||||||
|
|
||||||
# Set up the storage systems.
|
|
||||||
public_store = storage.storage_system_from_paste_config(
|
|
||||||
mgoblin_section, 'publicstore')
|
|
||||||
queue_store = storage.storage_system_from_paste_config(
|
|
||||||
mgoblin_section, 'queuestore')
|
|
||||||
|
|
||||||
workbench_manager = WorkbenchManager(
|
|
||||||
mgoblin_section.get(
|
|
||||||
'workbench_path', DEFAULT_WORKBENCH_DIR))
|
|
||||||
|
|
||||||
setup_globals(
|
|
||||||
db_connection=connection,
|
|
||||||
database=db,
|
|
||||||
public_store=public_store,
|
|
||||||
email_debug_mode=asbool(mgoblin_section.get('email_debug_mode')),
|
|
||||||
email_sender_address=mgoblin_section.get(
|
|
||||||
'email_sender_address',
|
|
||||||
'notice@mediagoblin.example.org'),
|
|
||||||
queue_store=queue_store,
|
|
||||||
workbench_manager=workbench_manager)
|
|
||||||
|
|
||||||
|
|
||||||
if os.environ['CELERY_CONFIG_MODULE'] == OUR_MODULENAME:
|
if os.environ['CELERY_CONFIG_MODULE'] == OUR_MODULENAME:
|
||||||
setup_self()
|
setup_self()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user