diff --git a/.env b/.env index f3c5180..43de358 100644 --- a/.env +++ b/.env @@ -5,10 +5,7 @@ DEBUG=true SQLALCHEMY_DATABASE_URI= MODULE_NAME=barker.main PROJECT_NAME=barker -POSTGRES_SERVER= -POSTGRES_USER= -POSTGRES_PASSWORD= -POSTGRES_DB= +RABBITMQ_URI= # openssl rand -hex 32 SECRET_KEY= diff --git a/barker/alembic/env.py b/barker/alembic/env.py index 3301eac..b988f25 100644 --- a/barker/alembic/env.py +++ b/barker/alembic/env.py @@ -1,10 +1,9 @@ import logging -from sqlalchemy import create_engine -from sqlalchemy import pool - from alembic import context from barker.core.config import settings +from sqlalchemy import create_engine, pool + logging.basicConfig() logging.getLogger("sqlalchemy.engine").setLevel(settings.ALEMBIC_LOG_LEVEL) @@ -15,6 +14,7 @@ logging.getLogger("alembic").setLevel(settings.ALEMBIC_LOG_LEVEL) from barker.models.auth import User # noqa + target_metadata = User.metadata # other values from the config, defined by the needs of env.py, @@ -55,10 +55,15 @@ def run_migrations_online(): and associate a connection with the context. """ - connectable = create_engine(settings.SQLALCHEMY_DATABASE_URI, poolclass=pool.NullPool,) + connectable = create_engine( + settings.SQLALCHEMY_DATABASE_URI, + poolclass=pool.NullPool, + ) with connectable.connect() as connection: - context.configure(connection=connection, target_metadata=target_metadata, compare_type=True) + context.configure( + connection=connection, target_metadata=target_metadata, compare_type=True + ) with context.begin_transaction(): context.run_migrations() diff --git a/barker/alembic/versions/8c06ac60d125_initial_commit.py b/barker/alembic/versions/8c06ac60d125_initial_commit.py index b4b2185..c9dc489 100644 --- a/barker/alembic/versions/8c06ac60d125_initial_commit.py +++ b/barker/alembic/versions/8c06ac60d125_initial_commit.py @@ -7,12 +7,13 @@ Create Date: 2020-06-04 08:14:34.132248 """ import uuid -from alembic import op import sqlalchemy as sa + +from alembic import op +from barker.models import Customer, DbSetting, ModifierCategory, Section, SettleOption +from barker.models.auth import Permission, User # noqa from sqlalchemy.dialects import postgresql -from barker.models import Section, ModifierCategory, SettleOption, Customer, DbSetting -from barker.models.auth import User, Permission # noqa # revision identifiers, used by Alembic. revision = "8c06ac60d125" @@ -137,7 +138,9 @@ def upgrade(): sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("name", sa.Unicode(length=255), nullable=False), sa.Column("section_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections")), + sa.ForeignKeyConstraint( + ["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections") + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_devices")), sa.UniqueConstraint("name", name=op.f("uq_devices_name")), ) @@ -149,7 +152,11 @@ def upgrade(): sa.Column("section_id", postgresql.UUID(), nullable=False), sa.Column("is_active", sa.Boolean(), nullable=False), sa.Column("sort_order", sa.Numeric(), nullable=False), - sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_food_tables_section_id_sections")), + sa.ForeignKeyConstraint( + ["section_id"], + ["sections.id"], + name=op.f("fk_food_tables_section_id_sections"), + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_food_tables")), sa.UniqueConstraint("name", name=op.f("uq_food_tables_name")), ) @@ -159,7 +166,11 @@ def upgrade(): sa.Column("customer_id", postgresql.UUID(), nullable=False), sa.Column("pax", sa.Numeric(), nullable=False), sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False), - sa.ForeignKeyConstraint(["customer_id"], ["customers.id"], name=op.f("fk_guest_book_customer_id_customers")), + sa.ForeignKeyConstraint( + ["customer_id"], + ["customers.id"], + name=op.f("fk_guest_book_customer_id_customers"), + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_guest_book")), ) op.create_table( @@ -184,18 +195,26 @@ def upgrade(): sa.Column("permission_id", postgresql.UUID(), nullable=False), sa.Column("role_id", postgresql.UUID(), nullable=False), sa.ForeignKeyConstraint( - ["permission_id"], ["permissions.id"], name=op.f("fk_role_permissions_permission_id_permissions") + ["permission_id"], + ["permissions.id"], + name=op.f("fk_role_permissions_permission_id_permissions"), + ), + sa.ForeignKeyConstraint( + ["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles") ), - sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles")), sa.PrimaryKeyConstraint("id", name=op.f("pk_role_permissions")), - sa.UniqueConstraint("permission_id", "role_id", name=op.f("uq_role_permissions_permission_id")), + sa.UniqueConstraint( + "permission_id", "role_id", name=op.f("uq_role_permissions_permission_id") + ), ) op.create_table( "sale_categories", sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("name", sa.Unicode(length=255), nullable=False), sa.Column("tax_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes")), + sa.ForeignKeyConstraint( + ["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes") + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_sale_categories")), sa.UniqueConstraint("name", name=op.f("uq_sale_categories_name")), ) @@ -211,18 +230,34 @@ def upgrade(): ["menu_categories.id"], name=op.f("fk_section_printers_menu_category_id_menu_categories"), ), - sa.ForeignKeyConstraint(["printer_id"], ["printers.id"], name=op.f("fk_section_printers_printer_id_printers")), - sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_section_printers_section_id_sections")), + sa.ForeignKeyConstraint( + ["printer_id"], + ["printers.id"], + name=op.f("fk_section_printers_printer_id_printers"), + ), + sa.ForeignKeyConstraint( + ["section_id"], + ["sections.id"], + name=op.f("fk_section_printers_section_id_sections"), + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_section_printers")), - sa.UniqueConstraint("menu_category_id", "section_id", name=op.f("uq_section_printers_menu_category_id")), + sa.UniqueConstraint( + "menu_category_id", + "section_id", + name=op.f("uq_section_printers_menu_category_id"), + ), ) op.create_table( "user_roles", sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False), sa.Column("role_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles")), - sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users")), + sa.ForeignKeyConstraint( + ["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles") + ), + sa.ForeignKeyConstraint( + ["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users") + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_user_roles")), sa.UniqueConstraint("user_id", "role_id", name=op.f("uq_user_roles_user_id")), ) @@ -240,10 +275,14 @@ def upgrade(): sa.Column("is_active", sa.Boolean(), nullable=False), sa.Column("sort_order", sa.Numeric(), nullable=False), sa.ForeignKeyConstraint( - ["menu_category_id"], ["menu_categories.id"], name=op.f("fk_products_menu_category_id_menu_categories") + ["menu_category_id"], + ["menu_categories.id"], + name=op.f("fk_products_menu_category_id_menu_categories"), ), sa.ForeignKeyConstraint( - ["sale_category_id"], ["sale_categories.id"], name=op.f("fk_products_sale_category_id_sale_categories") + ["sale_category_id"], + ["sale_categories.id"], + name=op.f("fk_products_sale_category_id_sale_categories"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_products")), sa.UniqueConstraint("name", "units", name=op.f("uq_products_name")), @@ -263,13 +302,23 @@ def upgrade(): sa.Column("reason", sa.Unicode(length=255), nullable=True), sa.Column("voucher_type", sa.Integer(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["customer_id"], ["customers.id"], name=op.f("fk_vouchers_customer_id_customers")), sa.ForeignKeyConstraint( - ["food_table_id"], ["food_tables.id"], name=op.f("fk_vouchers_food_table_id_food_tables") + ["customer_id"], + ["customers.id"], + name=op.f("fk_vouchers_customer_id_customers"), + ), + sa.ForeignKeyConstraint( + ["food_table_id"], + ["food_tables.id"], + name=op.f("fk_vouchers_food_table_id_food_tables"), + ), + sa.ForeignKeyConstraint( + ["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users") ), - sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users")), sa.PrimaryKeyConstraint("id", name=op.f("pk_vouchers")), - sa.UniqueConstraint("bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id")), + sa.UniqueConstraint( + "bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id") + ), sa.UniqueConstraint("kot_id", name=op.f("uq_vouchers_kot_id")), ) op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False) @@ -281,9 +330,17 @@ def upgrade(): sa.Column("food_table_id", postgresql.UUID(), nullable=False), sa.Column("date", sa.DateTime(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["food_table_id"], ["food_tables.id"], name=op.f("fk_kots_food_table_id_food_tables")), - sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users")), - sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers")), + sa.ForeignKeyConstraint( + ["food_table_id"], + ["food_tables.id"], + name=op.f("fk_kots_food_table_id_food_tables"), + ), + sa.ForeignKeyConstraint( + ["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users") + ), + sa.ForeignKeyConstraint( + ["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers") + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_kots")), sa.UniqueConstraint("code", name=op.f("uq_kots_code")), ) @@ -297,14 +354,20 @@ def upgrade(): sa.ForeignKeyConstraint( ["modifier_categories_id"], ["modifier_categories.id"], - name=op.f("fk_modifier_categories_products_modifier_categories_id_modifier_categories"), + name=op.f( + "fk_modifier_categories_products_modifier_categories_id_modifier_categories" + ), ), sa.ForeignKeyConstraint( - ["product_id"], ["products.id"], name=op.f("fk_modifier_categories_products_product_id_products") + ["product_id"], + ["products.id"], + name=op.f("fk_modifier_categories_products_product_id_products"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_modifier_categories_products")), sa.UniqueConstraint( - "product_id", "modifier_categories_id", name=op.f("uq_modifier_categories_products_product_id") + "product_id", + "modifier_categories_id", + name=op.f("uq_modifier_categories_products_product_id"), ), ) op.create_table( @@ -315,12 +378,20 @@ def upgrade(): sa.Column("guest_book_id", postgresql.UUID(), nullable=True), sa.Column("status", sa.Unicode(length=255), nullable=False), sa.ForeignKeyConstraint( - ["food_table_id"], ["food_tables.id"], name=op.f("fk_overview_food_table_id_food_tables") + ["food_table_id"], + ["food_tables.id"], + name=op.f("fk_overview_food_table_id_food_tables"), ), sa.ForeignKeyConstraint( - ["guest_book_id"], ["guest_book.id"], name=op.f("fk_overview_guest_book_id_guest_book") + ["guest_book_id"], + ["guest_book.id"], + name=op.f("fk_overview_guest_book_id_guest_book"), + ), + sa.ForeignKeyConstraint( + ["voucher_id"], + ["vouchers.id"], + name=op.f("fk_overview_voucher_id_vouchers"), ), - sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_overview_voucher_id_vouchers")), sa.PrimaryKeyConstraint("id", name=op.f("pk_overview")), sa.UniqueConstraint("food_table_id", name=op.f("uq_overview_food_table_id")), sa.UniqueConstraint("guest_book_id", name=op.f("uq_overview_guest_book_id")), @@ -332,24 +403,44 @@ def upgrade(): sa.Column("date", sa.DateTime(), nullable=False), sa.Column("voucher_id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False), - sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users")), - sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_reprints_voucher_id_vouchers")), + sa.ForeignKeyConstraint( + ["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users") + ), + sa.ForeignKeyConstraint( + ["voucher_id"], + ["vouchers.id"], + name=op.f("fk_reprints_voucher_id_vouchers"), + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_reprints")), ) op.create_index(op.f("ix_reprints_date"), "reprints", ["date"], unique=False) - op.create_index(op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False) + op.create_index( + op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False + ) op.create_table( "settlements", sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("voucher_id", postgresql.UUID(), nullable=False), sa.Column("settled", sa.Integer(), nullable=False), sa.Column("amount", sa.Numeric(), nullable=False), - sa.ForeignKeyConstraint(["settled"], ["settle_options.id"], name=op.f("fk_settlements_settled_settle_options")), - sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_settlements_voucher_id_vouchers")), + sa.ForeignKeyConstraint( + ["settled"], + ["settle_options.id"], + name=op.f("fk_settlements_settled_settle_options"), + ), + sa.ForeignKeyConstraint( + ["voucher_id"], + ["vouchers.id"], + name=op.f("fk_settlements_voucher_id_vouchers"), + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_settlements")), - sa.UniqueConstraint("voucher_id", "settled", name=op.f("uq_settlements_voucher_id")), + sa.UniqueConstraint( + "voucher_id", "settled", name=op.f("uq_settlements_voucher_id") + ), + ) + op.create_index( + op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False ) - op.create_index(op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False) op.create_table( "inventories", sa.Column("id", postgresql.UUID(), nullable=False), @@ -362,13 +453,29 @@ def upgrade(): sa.Column("tax_id", postgresql.UUID(), nullable=False), sa.Column("discount", sa.Numeric(), nullable=True), sa.Column("sort_order", sa.Numeric(), nullable=False), - sa.ForeignKeyConstraint(["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots")), - sa.ForeignKeyConstraint(["product_id"], ["products.id"], name=op.f("fk_inventories_product_id_products")), - sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes")), + sa.ForeignKeyConstraint( + ["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots") + ), + sa.ForeignKeyConstraint( + ["product_id"], + ["products.id"], + name=op.f("fk_inventories_product_id_products"), + ), + sa.ForeignKeyConstraint( + ["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes") + ), sa.PrimaryKeyConstraint("id", name=op.f("pk_inventories")), - sa.UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price", name=op.f("uq_inventories_kot_id")), + sa.UniqueConstraint( + "kot_id", + "product_id", + "is_happy_hour", + "price", + name=op.f("uq_inventories_kot_id"), + ), + ) + op.create_index( + op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False ) - op.create_index(op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False) op.create_table( "inventory_modifiers", sa.Column("id", postgresql.UUID(), nullable=False), @@ -376,20 +483,48 @@ def upgrade(): sa.Column("modifier_id", postgresql.UUID(), nullable=False), sa.Column("price", sa.Numeric(), nullable=False), sa.ForeignKeyConstraint( - ["inventory_id"], ["inventories.id"], name=op.f("fk_inventory_modifiers_inventory_id_inventories") + ["inventory_id"], + ["inventories.id"], + name=op.f("fk_inventory_modifiers_inventory_id_inventories"), ), sa.ForeignKeyConstraint( - ["modifier_id"], ["modifiers.id"], name=op.f("fk_inventory_modifiers_modifier_id_modifiers") + ["modifier_id"], + ["modifiers.id"], + name=op.f("fk_inventory_modifiers_modifier_id_modifiers"), ), sa.PrimaryKeyConstraint("id", name=op.f("pk_inventory_modifiers")), - sa.UniqueConstraint("inventory_id", "modifier_id", name=op.f("uq_inventory_modifiers_inventory_id")), + sa.UniqueConstraint( + "inventory_id", + "modifier_id", + name=op.f("uq_inventory_modifiers_inventory_id"), + ), ) - op.execute(Permission.__table__.insert().values(id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book")) - op.execute(Permission.__table__.insert().values(id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers")) - op.execute(Permission.__table__.insert().values(id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections")) - op.execute(Permission.__table__.insert().values(id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers")) - op.execute(Section.__table__.insert().values(id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main")) + op.execute( + Permission.__table__.insert().values( + id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book" + ) + ) + op.execute( + Permission.__table__.insert().values( + id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers" + ) + ) + op.execute( + Permission.__table__.insert().values( + id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections" + ) + ) + op.execute( + Permission.__table__.insert().values( + id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers" + ) + ) + op.execute( + Section.__table__.insert().values( + id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main" + ) + ) op.execute( ModifierCategory.__table__.insert().values( @@ -454,15 +589,25 @@ def upgrade(): op.execute( SettleOption.__table__.insert().values( - id=1, name="Unsettled", show_in_choices=False, display_group=1, is_print=True + id=1, + name="Unsettled", + show_in_choices=False, + display_group=1, + is_print=True, ) ) op.execute( - SettleOption.__table__.insert().values(id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False) + SettleOption.__table__.insert().values( + id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False + ) ) op.execute( SettleOption.__table__.insert().values( - id=3, name="Credit Card", show_in_choices=True, display_group=2, is_print=True + id=3, + name="Credit Card", + show_in_choices=True, + display_group=2, + is_print=True, ) ) op.execute( @@ -472,15 +617,25 @@ def upgrade(): ) op.execute( SettleOption.__table__.insert().values( - id=5, name="Bill To Company", show_in_choices=True, display_group=2, is_print=True + id=5, + name="Bill To Company", + show_in_choices=True, + display_group=2, + is_print=True, ) ) op.execute( - SettleOption.__table__.insert().values(id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True) + SettleOption.__table__.insert().values( + id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True + ) ) op.execute( SettleOption.__table__.insert().values( - id=7, name="Round Off", show_in_choices=False, display_group=1, is_print=False + id=7, + name="Round Off", + show_in_choices=False, + display_group=1, + is_print=False, ) ) op.execute( @@ -489,7 +644,9 @@ def upgrade(): ) ) op.execute( - SettleOption.__table__.insert().values(id=9, name="Void", show_in_choices=True, display_group=1, is_print=True) + SettleOption.__table__.insert().values( + id=9, name="Void", show_in_choices=True, display_group=1, is_print=True + ) ) op.execute( SettleOption.__table__.insert().values( @@ -498,7 +655,11 @@ def upgrade(): ) op.execute( Customer.__table__.insert().values( - id="2c716f4b-0736-429a-ad51-610d7c47cb5e", company="", name="Cash", phone="", address="" + id="2c716f4b-0736-429a-ad51-610d7c47cb5e", + company="", + name="Cash", + phone="", + address="", ) ) op.execute( diff --git a/barker/barker/celeryworker_pre_start.py b/barker/barker/celeryworker_pre_start.py new file mode 100644 index 0000000..2fc065a --- /dev/null +++ b/barker/barker/celeryworker_pre_start.py @@ -0,0 +1,19 @@ +import logging + + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +def init() -> None: + pass + + +def main() -> None: + logger.info("Initializing service") + init() + logger.info("Service finished initializing") + + +if __name__ == "__main__": + main() diff --git a/barker/barker/core/celery_app.py b/barker/barker/core/celery_app.py new file mode 100644 index 0000000..9a016ac --- /dev/null +++ b/barker/barker/core/celery_app.py @@ -0,0 +1,7 @@ +from barker.core.config import settings +from celery import Celery + + +celery_app = Celery("tasks", broker=settings.RABBITMQ_URI) + +celery_app.conf.task_routes = {"barker.worker.sent_to_printer": "main-queue"} diff --git a/barker/barker/core/config.py b/barker/barker/core/config.py index 32a39e9..e78c71a 100644 --- a/barker/barker/core/config.py +++ b/barker/barker/core/config.py @@ -18,23 +18,8 @@ class Settings(BaseSettings): PORT: int = 80 DEBUG: bool = False LOG_LEVEL: str = "NOTSET" - POSTGRES_SERVER: str = "" - POSTGRES_USER: str = "postgres" - POSTGRES_PASSWORD: str = "" - POSTGRES_DB: str = "" - SQLALCHEMY_DATABASE_URI: Optional[str] = None - - @validator("SQLALCHEMY_DATABASE_URI", pre=True) - def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any: - if isinstance(v, str): - return v - return PostgresDsn.build( - scheme="postgresql", - user=values.get("POSTGRES_USER"), - password=values.get("POSTGRES_PASSWORD"), - host=values.get("POSTGRES_SERVER"), - path=f"/{values.get('POSTGRES_DB') or ''}", - ) + SQLALCHEMY_DATABASE_URI: str = None + RABBITMQ_URI: str = None ALEMBIC_LOG_LEVEL: str = "INFO" ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN" diff --git a/barker/barker/routers/voucher/change.py b/barker/barker/routers/voucher/change.py index 11f6a1c..5e49891 100644 --- a/barker/barker/routers/voucher/change.py +++ b/barker/barker/routers/voucher/change.py @@ -4,8 +4,8 @@ from decimal import Decimal from typing import Optional import barker.schemas.voucher as schemas -from barker.models import VoucherType +from barker.models import VoucherType from fastapi import APIRouter, Depends, HTTPException, Security, status from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.orm import Session diff --git a/barker/barker/routers/voucher/save.py b/barker/barker/routers/voucher/save.py index 08cc0e5..f33a708 100644 --- a/barker/barker/routers/voucher/save.py +++ b/barker/barker/routers/voucher/save.py @@ -131,7 +131,7 @@ def do_save( raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail=f"You are not allowed to delete printed products." - f"\n In this case {product.full_name}", + f"\n In this case {product.full_name}", ) tax_rate = get_tax(product.sale_category.tax.rate, voucher_type) inv = Inventory( diff --git a/barker/barker/worker.py b/barker/barker/worker.py index c650506..2648aac 100644 --- a/barker/barker/worker.py +++ b/barker/barker/worker.py @@ -2,12 +2,11 @@ import re import socket import sys -from celery import Celery +from barker.core.celery_app import celery_app from celery.utils.log import get_task_logger # Create the celery app and get the logger -celery_app = Celery("tasks", broker="pyamqp://guest@localhost//") logger = get_task_logger(__name__) diff --git a/barker/worker-start.sh b/barker/worker-start.sh new file mode 100644 index 0000000..9770b5b --- /dev/null +++ b/barker/worker-start.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash +set -e + +python /app/barker/celeryworker_pre_start.py + +celery worker --app barker.worker --loglevel info --queues main-queue --concurrency 1