Skip to content

Commit 72b8ee6

Browse files
committed
use bootstrap in redis [appendix_bootstrap_ends]
1 parent 310697b commit 72b8ee6

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
1+
from __future__ import annotations
2+
from typing import TYPE_CHECKING
13
import json
24
import logging
35
import redis
4-
5-
from allocation import config
6+
from allocation import bootstrap, config
67
from allocation.domain import commands
7-
from allocation.adapters import notifications, orm, redis_eventpublisher
8-
from allocation.service_layer import messagebus, unit_of_work
8+
if TYPE_CHECKING:
9+
from allocation.service_layer import messagebus
910

1011
logger = logging.getLogger(__name__)
1112

1213
r = redis.Redis(**config.get_redis_host_and_port())
1314

14-
def get_bus():
15-
uow = unit_of_work.SqlAlchemyUnitOfWork()
16-
bus = messagebus.MessageBus(
17-
uow=uow,
18-
notifications=notifications.EmailNotifications(),
19-
publish=redis_eventpublisher.publish
20-
)
21-
uow.bus = bus
22-
return bus
23-
2415

2516
def main():
2617
logger.info('Redis pubsub starting')
18+
bus = bootstrap.bootstrap()
2719
pubsub = r.pubsub(ignore_subscribe_messages=True)
2820
pubsub.subscribe('change_batch_quantity')
29-
bus = get_bus()
3021

3122
for m in pubsub.listen():
3223
handle_change_batch_quantity(m, bus)
@@ -40,5 +31,4 @@ def handle_change_batch_quantity(m, bus: messagebus.MessageBus):
4031

4132

4233
if __name__ == '__main__':
43-
orm.start_mappers()
4434
main()

0 commit comments

Comments
 (0)