def clean_action(args): LOG.info('Cleaning action table') db_string = get_global_config(args.dir).get('db_string') db = database.connect(db_string) actions = database.get_action(db, start=args.start, end=args.end) LOG.info('Got %d actions between %s and %s', len(actions), args.start, args.end) ids_to_delete = [action.id for action in actions] if args.execute: database.delete_row(db, database.Action, ids_to_delete)
def _check_action_interval(self, sensor_data, sensor_action_id, action_interval): try: last_actions = database.get_action(self.db, board_ids=sensor_data['board_id'], sensor_type=sensor_data['sensor_type'], sensor_action_id=sensor_action_id, last_available=1) except OperationalError as e: last_actions = None LOG.error("Fail to get action '%s'", e) if not last_actions: last_action = 0 else: last_action = last_actions[0].last_update return utils.time_offset(-last_action) > action_interval