Skip to content

Commit 1b4c664

Browse files
committed
redis eventconsumer first cut [redis_eventconsumer_first_cut]
1 parent 5bb7055 commit 1b4c664

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import logging
3+
import redis
4+
5+
from allocation import config
6+
from allocation.domain import commands
7+
from allocation.adapters import orm
8+
from allocation.service_layer import messagebus, unit_of_work
9+
10+
logger = logging.getLogger(__name__)
11+
12+
r = redis.Redis(**config.get_redis_host_and_port())
13+
14+
15+
def main():
16+
orm.start_mappers()
17+
pubsub = r.pubsub(ignore_subscribe_messages=True)
18+
pubsub.subscribe('change_batch_quantity')
19+
20+
for m in pubsub.listen():
21+
handle_change_batch_quantity(m)
22+
23+
24+
def handle_change_batch_quantity(m):
25+
logging.debug('handling %s', m)
26+
data = json.loads(m['data'])
27+
cmd = commands.ChangeBatchQuantity(ref=data['batchref'], qty=data['qty'])
28+
messagebus.handle(cmd, uow=unit_of_work.SqlAlchemyUnitOfWork())
29+
30+
if __name__ == '__main__':
31+
main()

0 commit comments

Comments
 (0)