Skip to content

Commit 6a4cb0e

Browse files
committed
redis initialises bus [redis_initialises_bus]
1 parent 1c2dbd4 commit 6a4cb0e

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/allocation/entrypoints/redis_eventconsumer.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,40 @@
44

55
from allocation import config
66
from allocation.domain import commands
7-
from allocation.adapters import orm
7+
from allocation.adapters import email, orm, redis_eventpublisher
88
from allocation.service_layer import messagebus, unit_of_work
99

1010
logger = logging.getLogger(__name__)
1111

1212
r = 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

1525
def 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

3141
if __name__ == '__main__':
42+
orm.start_mappers()
3243
main()

0 commit comments

Comments
 (0)