Example #1
0
def update_db(end_date, start_date=None):
    if start_date is None:
        try:
            start = get_start_time()
        except RuntimeError:
            return
    else:
        start = datetime.datetime.strptime(start_date, '%Y-%m-%dT%H:%M:%S')

    end = datetime.datetime.strptime(end_date, '%Y-%m-%dT%H:%M:%S')

    logger.info('Filling cache into DB')
    logger.info('Start Time: %s, End time: %s', start, end)
    try:
        dao_sess.begin()
        insert_missing_queues(start, end)
        insert_missing_agents()
        dao_sess.commit()

        dao_sess.begin()
        queue.remove_between(dao_sess, start, end)
        agent.remove_after_start(dao_sess, start)
        queue.fill_simple_calls(dao_sess, start, end)
        dao_sess.commit()

        agent.insert_periodic_stat(dao_sess, start, end)

        for period_start in queue_log_dao.hours_with_calls(dao_sess, start, end):
            period_end = period_start + datetime.timedelta(hours=1) - datetime.timedelta(microseconds=1)
            queue.fill_calls(dao_sess, period_start, period_end)
            queue.insert_periodic_stat(dao_sess, period_start, period_end)
    except (IntegrityError, KeyboardInterrupt):
        _clean_up_after_error()
Example #2
0
    def test_fill_calls(self, mock_fill_timeout_call, mock_fill_abandoned_call):
        start = datetime.datetime(2012, 1, 1)
        end = datetime.datetime(2012, 1, 1, 4, 59, 59, 999999)

        queue.fill_calls(dao_sess, start, end)

        mock_fill_abandoned_call.assert_called_once_with(dao_sess, start, end)
        mock_fill_timeout_call.assert_called_once_with(dao_sess, start, end)
Example #3
0
    def test_fill_calls(self, mock_fill_timeout_call,
                        mock_fill_abandoned_call):
        start = datetime.datetime(2012, 1, 1)
        end = datetime.datetime(2012, 1, 1, 4, 59, 59, 999999)

        queue.fill_calls(dao_sess, start, end)

        mock_fill_abandoned_call.assert_called_once_with(dao_sess, start, end)
        mock_fill_timeout_call.assert_called_once_with(dao_sess, start, end)