def bootstrap( start_orm: bool = True, uow: unit_of_work.AbstractUnitOfWork = unit_of_work.SqlAlchemyUnitOfWork(), notifications: AbstractNotifications = None, publish: Callable = redis_eventpublisher.publish, ) -> messagebus.MessageBus: if notifications is None: notifications = EmailNotifications() if start_orm: orm.start_mappers() dependencies = { 'uow': uow, 'notifications': notifications, 'publish': publish } injected_event_handlers = { event_type: [ inject_dependencies(handler, dependencies) for handler in event_handlers ] for event_type, event_handlers in handlers.EVENT_HANDLERS.items() } injected_command_handlers = { command_type: inject_dependencies(handler, dependencies) for command_type, handler in handlers.COMMAND_HANDLERS.items() } return messagebus.MessageBus( uow=uow, event_handlers=injected_event_handlers, command_handlers=injected_command_handlers, )
from datetime import datetime from flask import Flask, jsonify, request from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker import sys sys.path.append( r'C:\Users\vlonc_000\Documents\08 code\learnproj\learnproj\code') from src.allocation import config from src.allocation.domain import model from src.allocation.adapters import orm, repository from src.allocation.service_layer import services, unit_of_work orm.start_mappers() #get_session = sessionmaker(bind=create_engine(config.get_postgres_uri())) app = Flask(__name__) @app.route("/add_batch", methods=['POST']) def add_batch(): uow = unit_of_work.SqlAlchemyUnitOfWork() eta = request.json['eta'] if eta is not None: eta = datetime.fromisoformat(eta).date() services.add_batch(request.json['ref'], request.json['sku'], request.json['qty'], eta, uow) return 'OK', 201 @app.route("/allocate", methods=['POST']) def allocate_endpoint():
def postgres_session(postgres_db): start_mappers() yield sessionmaker(bind=postgres_db)() clear_mappers()
def session(in_memory_db): start_mappers() yield sessionmaker(bind=in_memory_db)() clear_mappers()
def postgres_session_factory(postgres_db): start_mappers() yield sessionmaker(bind=postgres_db) clear_mappers()
def mappers(): start_mappers() yield clear_mappers()