Esempio n. 1
0
 def test_get_ms_days(self):
     delta = datetime.timedelta(days=3,
                                seconds=34,
                                milliseconds=115,
                                microseconds=222)
     ms = utils.get_ms(delta)
     self.assertEqual(259234115.222, ms)
Esempio n. 2
0
    def process_response(self, req, resp, resource):
        in_ts = req.context['in_ts']
        out_ts = datetime.datetime.utcnow()
        req.context['out_ts'] = out_ts
        elapsed = get_ms(out_ts - in_ts)
        req.context['elapsed'] = elapsed

        if not req.context['internal']:
            session = req.context['session']
            match = {'_id': session}
            update = {
                '$set': {
                    'out_ts': out_ts,
                    'elapsed': get_ms(out_ts - in_ts),
                    'response': resp.body
                }
            }
            self.mongodb.session.update_one(match, update)
Esempio n. 3
0
    def end_session(self, response, status='OK'):
        in_ts = self.context['in_ts']
        out_ts = datetime.datetime.utcnow()
        self.context['out_ts'] = out_ts
        elapsed = get_ms(out_ts - in_ts)
        self.context['elapsed'] = elapsed

        if not self.context['internal']:
            match = {'_id': self.session}
            elapsed = get_ms(out_ts - in_ts)
            update = {
                '$set': {
                    'out_ts': out_ts,
                    'elapsed': elapsed,
                    'response': response,
                    'status': status,
                    'alive': False,
                }
            }
            self.mongodb.session.update_one(match, update)

        self.logger.info("Ending session %s. Status: %s, Elapsed: %sms",
                         self.session, status, elapsed)
Esempio n. 4
0
    def process_response(self, req, resp, resource):
        in_ts = req.context['in_ts']
        out_ts = req.context.get('out_ts') or datetime.datetime.utcnow()
        elapsed = req.context.get('elapsed') or get_ms(out_ts - in_ts)

        resp.body = {
            'status': resp.status,
            'pid': os.getpid(),
            'host': socket.gethostname(),
            'results': resp.body,
            'session': req.context.get('session'),
            'in_ts': in_ts,
            'out_ts': out_ts,
            'elapsed': elapsed
        }
Esempio n. 5
0
    def update_audit(self, message, exception):
        end_ts = datetime.datetime.utcnow()

        audit = {
            'end_ts': end_ts,
            'elapsed': utils.get_ms(end_ts - self.start_ts),
        }
        if exception:
            audit['status'] = 'EXCEPTION'
            audit['exception'] = exception
            audit['request'] = self.initial_message
            audit['message'] = message

        else:
            audit['status'] = 'OK'

        match = {'_id': self.aid}
        update = {'$set': audit}
        self.auditdb.actions.update(match, update)
Esempio n. 6
0
 def test_get_ms_some_milliseconds(self):
     delta = datetime.timedelta(milliseconds=15, microseconds=222)
     ms = utils.get_ms(delta)
     self.assertEqual(15.222, ms)