first commit
This commit is contained in:
24
worker/worker.py
Normal file
24
worker/worker.py
Normal file
@ -0,0 +1,24 @@
|
||||
from pymongo import MongoClient
|
||||
from redis import Redis
|
||||
import json
|
||||
|
||||
redis_client = Redis(host='redis', port=6379, decode_responses=True)
|
||||
mongo_client = MongoClient("mongodb://mongo:27017")
|
||||
mongo_db = mongo_client["logs"]
|
||||
mongo_col = mongo_db["actions"]
|
||||
|
||||
def transfer_actions():
|
||||
actions = []
|
||||
while True:
|
||||
entry = redis_client.lpop("user_actions")
|
||||
if entry is None:
|
||||
break
|
||||
actions.append(json.loads(entry))
|
||||
|
||||
if actions:
|
||||
mongo_col.insert_many(actions)
|
||||
print(f"Transferred {len(actions)} actions to MongoDB")
|
||||
|
||||
if __name__ == "__main__":
|
||||
transfer_actions()
|
||||
|
Reference in New Issue
Block a user