-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue_manager.py
37 lines (29 loc) · 1009 Bytes
/
queue_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import json
import sys
import time
import os
from common.rabbitmq import RabbitMqClient
from services.event_service import EventService
def main():
client = RabbitMqClient
try:
while 1:
start = time.time()
events = EventService.get_all_events()
if len(events) > 0:
for event in events:
client.channel.basic_publish(exchange='', routing_key=os.environ['RABBITMQ_QUEUE'],
body=f"{json.dumps(event.__dict__)}")
EventService.mark_event_as_in_queue(event.eventID)
print(f"Inserted {len(events)} events into queue")
else:
print(f"Inserted 0 events into queue")
print(f"Duration: {time.time() - start}")
time.sleep(1)
except:
print("Unexpected error:", sys.exc_info()[0])
raise
finally:
client.connection.close()
if __name__ == "__main__":
main()