2016-01-29 01:34:12 +00:00
|
|
|
import os
|
|
|
|
import importlib
|
2015-11-15 08:23:57 +00:00
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
2015-11-15 18:31:58 +00:00
|
|
|
from celery import Celery
|
2015-11-15 08:23:57 +00:00
|
|
|
from celery.signals import worker_init, worker_shutdown
|
|
|
|
|
2016-01-29 01:34:12 +00:00
|
|
|
os.environ.setdefault('OGN_CONFIG_MODULE', 'config.default')
|
|
|
|
config = importlib.import_module(os.environ['OGN_CONFIG_MODULE'])
|
2015-11-15 08:23:57 +00:00
|
|
|
|
2015-11-15 18:31:58 +00:00
|
|
|
|
2015-11-15 08:23:57 +00:00
|
|
|
@worker_init.connect
|
|
|
|
def connect_db(signal, sender):
|
|
|
|
# Load settings like DB_URI...
|
2016-01-29 01:34:12 +00:00
|
|
|
engine = create_engine(config.SQLALCHEMY_DATABASE_URI, echo=False)
|
2015-11-15 08:23:57 +00:00
|
|
|
|
|
|
|
Session = sessionmaker(bind=engine)
|
|
|
|
sender.app.session = Session()
|
|
|
|
|
2015-11-15 18:31:58 +00:00
|
|
|
|
2015-11-15 08:23:57 +00:00
|
|
|
@worker_shutdown.connect
|
|
|
|
def close_db(signal, sender):
|
|
|
|
sender.app.session.close()
|
|
|
|
|
|
|
|
|
2016-01-29 01:34:12 +00:00
|
|
|
app = Celery('ogn.collect',
|
|
|
|
include=["ogn.collect.database",
|
2016-01-29 04:25:35 +00:00
|
|
|
"ogn.collect.logbook",
|
2017-12-12 20:46:21 +00:00
|
|
|
"ogn.collect.stats",
|
2016-07-03 07:25:40 +00:00
|
|
|
"ogn.collect.takeoff_landing",
|
2016-02-04 17:31:58 +00:00
|
|
|
])
|
2016-01-29 01:34:12 +00:00
|
|
|
|
|
|
|
app.config_from_envvar("OGN_CONFIG_MODULE")
|