-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
41 lines (33 loc) · 1.11 KB
/
worker.py
File metadata and controls
41 lines (33 loc) · 1.11 KB
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
38
39
40
41
import logging
import os
import socket
import sys
from margay.sdk.config import Config
from margay.sdk.logger import SDKLogger
from margay.sdk.protocol import RawMessage
from margay.sdk.publisher import Publisher
from margay.sdk.subscriber import Subscriber
class SimpleWorker(Subscriber):
publisher: Publisher
def __init__(self, pub, *args, **kwargs):
super().__init__(*args, **kwargs)
self.publisher = pub
def process(self, message: RawMessage):
response = f"Respond to -> {message.body}"
self.publisher.publish_raw(
response,
sender=socket.gethostname(),
recipient=message.headers[Config.protocol.sender],
)
if __name__ == "__main__":
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
handlers=[logging.StreamHandler(sys.stdout)],
)
SDKLogger.setLevel(logging.DEBUG)
Config.set("queue", "VanillaWorkerQueue")
Config.set("dsn", os.getenv("MARGAY_TRANSPORT_DSN"))
publisher = Publisher()
worker = SimpleWorker(publisher)
worker.run()