def get_order(): if db.is_closed(): db.connect() order = Order.get_or_none(Order.is_processing == False) if not order: return order.is_processing = True order.save() if not db.is_closed(): db.close() return order
def db_close(response): ''' Close the database connection after each request. ''' logging.debug("Closing database connection.") if not db.is_closed(): db.close() else: logging.debug("Database connection already closed.") logging.debug("Closed database connection.") return response
def disconnect_db(response): '''Disconnect from db after handling request''' if not db.is_closed(): db.close() return response
def connect_db(): '''Connect to db before request made''' if db.is_closed(): db.connect()
def _db_close(exc): if not db.is_closed(): db.close()
def after(req): if not db.is_closed(): db.close() return req
def before(): if db.is_closed(): db.connect()
def open_db(): if db.is_closed(): db.connect()
def close_db(resp): if not db.is_closed(): db.close() return resp
def connect_db(): """Connect to db before request made""" if db.is_closed(): db.connect()
def disconnect_db(): if not db.is_closed(): db.close() print('Processing finished') sys.stdout.flush()
def connect_db(): if db.is_closed(): db.connect()