def shutdown_session(exception=None): """ When the http session is over this kills the database session. :returns: none """ db_session.remove()
def shutdown_session(exception=None): """ Method closes database session after app closes or request is completed :return: None """ if exception: print("Exception encountered: {}".format(repr(exception))) db_session.remove()
def database(): db_session.close() db_session.remove() EntityDeclarativeBase.metadata.create_all(engine) yield db_session db_session.close() db_session.remove() EntityDeclarativeBase.metadata.drop_all(engine)
def tearDown(self): from app.entities.datasource import DataSourceEntity uploads = [ datasource.location for datasource in DataSourceEntity.query.all() ] for upload in uploads: os.remove(upload) db_session.close() db_session.remove()
def shutdown_session(response_or_exc): try: sb.commit() except Exception as e: # logging.exception(e) pass finally: sb.remove() return response_or_exc
def get_records(call_model, event_model, get_date): print('entering get_records') if call_model and event_model: # Get records by date call_statement = call_model.src_statement(get_date) event_statement = event_model.src_statement(get_date) # Get records for the CallTable call_data_ptr = pg_session.execute(call_statement) call_data_records = results_to_dict( call_data_ptr) # Returns list of dicts # Get records for the EventTable event_data_ptr = pg_session.execute(event_statement) event_data_records = results_to_dict( event_data_ptr) # Returns list of dicts # Convert event: records -> event model -> event event_data = [ event_model(**event_record) for event_record in event_data_records ] for foreign_record in call_data_records: call = call_model(**foreign_record) # this sucks right now for call_event in [ call_event for call_event in event_data if call_event.call_id == call.call_id ]: call.add_event(call_event) # print('adding call', call.call_id, flush=True) # Add foreign records to current session db_session.add(call) try: db_session.commit() except IntegrityError: print('Records exist.') pg_session.remove() db_session.remove()
def report_task(start, end): success = False # Create a pyexcel table with the appropriate defaults by column name prepared_report = make_pyexcel_table( current_app.config['sla_report_headers'], list(current_app.config['CLIENTS']), current_app.config['sla_default_row']) try: record_query = get_records(db_session, start, end) record_list = record_query.all() # Index the query. Group columns from EventTable (c_event) to the call from CallTable (c_call) cached_results = prepare_records(record_list) # Consume query data report = process_report(prepared_report, cached_results) report.name = 'sla_report' for rd in current_app.config['sla_row_data']: make_programmatic_column(report, **rd) # Stringify each cell format_table(report) cache_report(db_session, start, end, report) except Exception as e: print(e) db_session.rollback() else: db_session.commit() # Set success flag on commit success = True finally: db_session.remove() return success
def setUp(self): db_session.close() db_session.remove() EntityDeclarativeBase.metadata.drop_all(engine) EntityDeclarativeBase.metadata.create_all(engine)
def remove_db_session(exception): db_session.remove()
def after_return(self, status, retval, task_id, args, kwargs, einfo): db_session.remove()
def on_failure(self, exc, task_id, args, kwargs, einfo): db_session.remove()
def session_clear(exception=None): db_session.remove() if exception and db_session.is_active: db_session.rollback()
def cleanup(resp_or_exception): db_session.remove()
def tearDown(self): with self.app.app_context(): db_session.remove()
def tearDown(self): db.reflect() db.drop_all() db_session.remove()
def on_fork_close_session(**kwargs): if db_session is not None: db_session.remove()
def teardown_database(exception=None): db_session.remove()
def shutdown_session(exception=None): db_session.remove()
def teardown_request(exception): db_session.close() db_session.remove()
def process_report(in_process_report, records): for call, events in records: # Dialed party number is the client row_name = str(call.dialed_party_number) if row_name in in_process_report.rownames and time( hour=7) <= call.start_time.time() <= time(hour=19): call_duration = call.end_time - call.start_time talking_time = events.get(4, timedelta(0)) voicemail_time = events.get(10, timedelta(0)) hold_time = sum([ events.get(event_type, timedelta(0)) for event_type in (5, 6, 7) ], timedelta(0)) wait_duration = call_duration - talking_time - hold_time # A live-answered call has > 0 seconds of agent talking time if talking_time > timedelta(0): in_process_report[row_name, 'I/C Presented'] += 1 in_process_report[row_name, 'I/C Live Answered'] += 1 in_process_report[row_name, 'Average Incoming Duration'] += talking_time in_process_report[row_name, 'Average Wait Answered'] += wait_duration # Qualify calls by duration if wait_duration <= timedelta(seconds=15): in_process_report[row_name, 'Calls Ans Within 15'] += 1 elif wait_duration <= timedelta(seconds=30): in_process_report[row_name, 'Calls Ans Within 30'] += 1 elif wait_duration <= timedelta(seconds=45): in_process_report[row_name, 'Calls Ans Within 45'] += 1 elif wait_duration <= timedelta(seconds=60): in_process_report[row_name, 'Calls Ans Within 60'] += 1 elif wait_duration <= timedelta(seconds=999): in_process_report[row_name, 'Calls Ans Within 999'] += 1 else: in_process_report[row_name, 'Call Ans + 999'] += 1 if wait_duration > in_process_report[ row_name, 'Longest Waiting Answered']: in_process_report[ row_name, 'Longest Waiting Answered'] = wait_duration # A voice mail is not live answered and last longer than 20 seconds elif voicemail_time > timedelta(seconds=20): in_process_report[row_name, 'I/C Presented'] += 1 in_process_report[row_name, 'Voice Mails'] += 1 in_process_report[row_name, 'Average Wait Lost'] += call_duration # An abandoned call is not live answered and last longer than 20 seconds elif call_duration > timedelta(seconds=20): in_process_report[row_name, 'I/C Presented'] += 1 in_process_report[row_name, 'I/C Abandoned'] += 1 in_process_report[row_name, 'Average Wait Lost'] += call_duration db_session.remove() return in_process_report
def teardown(): db_session.remove()