Created
May 14, 2020 06:23
-
-
Save avneesh91/30006859f052f0c584fc490a64c4f716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Script for picking up changes from the change stream | |
''' | |
import os | |
import json | |
import pymongo | |
from bson.json_util import dumps | |
from bson import ObjectId | |
client = pymongo.MongoClient('mongodb://localhost:27017/') | |
db = client['test'] | |
def handle_event_expiry(id): | |
print(id) | |
events = db.notifications.find({'event_id': ObjectId(id)}) | |
for i in events: | |
print(f'processing events {i}') | |
change_stream = db.expiry_event.watch() | |
for change in change_stream: | |
event = json.loads(dumps(change)) | |
if event.get('operationType') == 'delete': | |
expired_event = event.get('documentKey', {}).get('_id', {}).get('$oid') | |
handle_event_expiry(expired_event) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment