diff --git a/bin/integrity_check.py b/bin/integrity_check.py index e777a25c0b769b64d52c1b17e6d42ce5f16d43d4..c8ee53a2b1e2d2fe7ad4ecdaf67e4c51f1c4f88b 100755 --- a/bin/integrity_check.py +++ b/bin/integrity_check.py @@ -10,7 +10,8 @@ from api.jobs.gears import get_gear_by_name # Methods should return true if all integrity checks passed INTEGRITY_CHECKS = { - "rule_alg": "Confirm alg keys in rules table can be resolved to gear in gear table" + "rule_alg" : "Confirm alg keys in rules table can be resolved to gear in gear table", + "session_length" : "Confirm there are no sessions whose acquisition timestamps span more than 3 hours" } @@ -33,6 +34,25 @@ def rule_alg(): return not errors +def session_length(): + errors = False + + pipeline = [ + {'$match': {'timestamp': {'$ne': None}}}, + {'$group': {'_id': '$session', 'min_timestamp': { '$min': '$timestamp' }, 'max_timestamp': { '$max': '$timestamp' }}}, + {'$project': {'_id': '$_id', 'diff': { '$subtract': ['$max_timestamp', '$min_timestamp']}}}, + {'$match': {'diff': {'$gt': 10800000}}} + ] + + results = config.db.command('aggregate', 'acquisitions', pipeline=pipeline)['result'] + if len(results) > 0: + errors = True + logging.warning('There are {} sessions that span 3 hours.'.format(len(results))) + for r in results: + logging.warning('Session {} spans {} minutes'.format(r['_id'], r['diff']/60000)) + + return not errors + if __name__ == '__main__': try: