File tree Expand file tree Collapse file tree
src/allocation/entrypoints Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55from allocation import config
66from allocation .domain import commands
7- from allocation .adapters import orm
7+ from allocation .adapters import email , orm , redis_eventpublisher
88from allocation .service_layer import messagebus , unit_of_work
99
1010logger = logging .getLogger (__name__ )
1111
1212r = redis .Redis (** config .get_redis_host_and_port ())
1313
14+ def get_bus ():
15+ uow = unit_of_work .SqlAlchemyUnitOfWork ()
16+ bus = messagebus .MessageBus (
17+ uow = uow ,
18+ send_mail = email .send ,
19+ publish = redis_eventpublisher .publish
20+ )
21+ uow .bus = bus
22+ return bus
23+
1424
1525def main ():
16- orm .start_mappers ()
1726 pubsub = r .pubsub (ignore_subscribe_messages = True )
1827 pubsub .subscribe ('change_batch_quantity' )
28+ bus = get_bus ()
1929
2030 for m in pubsub .listen ():
21- handle_change_batch_quantity (m )
31+ handle_change_batch_quantity (m , bus )
2232
2333
24- def handle_change_batch_quantity (m ):
34+ def handle_change_batch_quantity (m , bus : messagebus . MessageBus ):
2535 logging .debug ('handling %s' , m )
2636 data = json .loads (m ['data' ])
2737 cmd = commands .ChangeBatchQuantity (ref = data ['batchref' ], qty = data ['qty' ])
28- messagebus .handle (cmd , uow = unit_of_work . SqlAlchemyUnitOfWork () )
38+ bus .handle (cmd )
2939
3040
3141if __name__ == '__main__' :
42+ orm .start_mappers ()
3243 main ()
You can’t perform that action at this time.
0 commit comments