File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import json
2+ import logging
3+ from dataclasses import asdict
4+ import redis
5+
6+ from allocation import config , orm , services , unit_of_work
7+
8+ logger = logging .getLogger (__name__ )
9+
10+ r = redis .Redis (** config .get_redis_host_and_port ())
11+
12+
13+ def main ():
14+ orm .start_mappers ()
15+ pubsub = r .pubsub (ignore_subscribe_messages = True )
16+ pubsub .subscribe ('change_batch_quantity' )
17+
18+ for m in pubsub .listen ():
19+ handle_change_batch_quantity (m )
20+
21+
22+ def handle_change_batch_quantity (m ):
23+ logging .debug ('handling %s' , m )
24+ data = json .loads (m ['data' ])
25+ services .change_batch_quantity (
26+ ref = data ['batchref' ], qty = data ['qty' ],
27+ uow = unit_of_work .SqlAlchemyUnitOfWork (),
28+ )
29+
30+
31+ def publish (channel , event ):
32+ logging .debug ('publishing: channel=%s, event=%s' , channel , event )
33+ r .publish (channel , json .dumps (asdict (event )))
34+
35+
36+ if __name__ == '__main__' :
37+ main ()
You can’t perform that action at this time.
0 commit comments