def put_pet(pet_id, pet): p = db_session.query(orm.Pet).filter(orm.Pet.id == pet_id).one_or_none() pet['id'] = pet_id if p is not None: logging.info('Updating pet %s..', pet_id) p.update(**pet) else: logging.info('Creating pet %s..', pet_id) pet['created'] = datetime.datetime.utcnow() db_session.add(orm.Pet(**pet)) db_session.commit() return NoContent, (200 if p is not None else 201)
out: dict = kinesis_client.get_records(ShardIterator=shard_it, Limit=2) shard_it = out["NextShardIterator"] data = None records = out['Records'] if records: data = out['Records'][0]['Data'].decode() logging.info('found data: %s', data) if data is not None: pet = json.loads(data) pet_id = pet['id'] p = db_session.query(orm.Pet).filter(orm.Pet.id == pet_id).one_or_none() if p is not None: logging.info('Updating pet %s..', pet_id) p.update(**pet) else: logging.info('Creating pet %s..', pet_id) pet['created'] = datetime.datetime.utcnow() db_session.add(orm.Pet(**pet)) db_session.commit() time.sleep(5) logging.info('tear down stream ... ') kinesis_client.delete_stream(StreamName='Pets', EnforceConsumerDeletion=True)