<s> import os <EOL> from celery import Celery <EOL> from flask import Flask <EOL> from database import migrate , db <EOL> from api import api <EOL> config_variable_name = '<STR_LIT>' <EOL> default_config_path = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> os . environ . setdefault ( config_variable_name , default_config_path ) <EOL> def create_app ( config_file = None , settings_override = None ) : <EOL> app = Flask ( __name__ ) <EOL> if config_file : <EOL> app . config . from_pyfile ( config_file ) <EOL> else : <EOL> app . config . from_envvar ( config_variable_name ) <EOL> if settings_override : <EOL> app . config . update ( settings_override ) <EOL> init_app ( app ) <EOL> return app <EOL> def init_app ( app ) : <EOL> db . init_app ( app ) <EOL> migrate . init_app ( app , db ) <EOL> api . init_app ( app ) <EOL> def create_celery_app ( app = None ) : <EOL> app = app or create_app ( ) <EOL> celery = Celery ( app . name , broker = app . config [ '<STR_LIT>' ] ) <EOL> celery . conf . update ( app . config ) <EOL> TaskBase = celery . Task <EOL> class ContextTask ( TaskBase ) : <EOL> abstract = True <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> with app . app_context ( ) : <EOL> return TaskBase . __call__ ( self , * args , ** kwargs ) <EOL> celery . Task = ContextTask <EOL> return celery </s>
