Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
a17380229 committed Dec 14, 2020
0 parents commit 7012912
Show file tree
Hide file tree
Showing 53 changed files with 2,280 additions and 0 deletions.
Empty file added .dockerignore
Empty file.
1 change: 1 addition & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEBUG=True
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.idea
.venv
.env
.env.dev
.cache
.coverage
.mypy_cache
.scannerwork
*.xml
**/__pycache__
.DS_Store
.pylintrc
venv
.vscode
docker-compose-local-db.yml
logs
tox.ini
.tox/
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright Ⓒ 2020 "Sberbank Real Estate Center" Limited Liability Company.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# async_boilerplate

[![License: MIT](https://img.shields.io/github/license/domclick/async_boilerplate)](https://github.com/domclick/async_boilerplate/blob/master/LICENSE.md)

Пример асинхронного веб-сервера на Sanic.

Статья на Habr - https://habr.com/ru/company/domclick/blog/531254/

Основной функционал:
- Веб сервер
- Работа с очередями rabbitMQ
- Запуск периодических заданий


## Установка
Для работы необходим Python версии 3.8

Зависимости ставятся командой `pip install -r requirements.txt`

## Команды для запуска
Для локального запуска необходимо поднять бд и rabbitMQ командой `docker-compose up` и прогнать миграции командой `alembic upgrade head`

Веб-сервер — `python manage.py run`

Консьюмеры — `python manage.py consume`

Кроны — `python manage.py schedule`


## Author
- [Semin Ivan](https://github.com/iasemin) (Author)

## Contributor Notice

We are always open for contributions. Feel free to submit an issue
or a PR. However, when submitting a PR we will ask you to sign
our [CLA (Contributor License Agreement)][cla-text] to confirm that you
have the rights to submit your contributions and to give us the rights
to actually use them.

When submitting a PR our special bot will ask you to review and to sign
our [CLA][cla-text]. This will happen only once for all our GitHub repositories.

## License

Copyright Ⓒ 2020 ["Sberbank Real Estate Center" Limited Liability Company](https://domclick.ru/).

[MIT License](./LICENSE.md)
83 changes: 83 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
script_location = alembic

# template used to generate migration files
file_template = %%(year)d%%(month).2d%%(day).2d_%%(hour).2d%%(minute).2d_%%(rev)s_%%(slug)s

# timezone to use when rendering the date
# within the migration file as well as the filename.
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; this defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks=black
# black.type=console_scripts
# black.entrypoint=black
# black.options=-l 79

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

95 changes: 95 additions & 0 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""
Copyright Ⓒ 2020 "Sberbank Real Estate Center" Limited Liability Company. Licensed under the MIT license.
Please, see the LICENSE.md file in project's root for full licensing information.
"""
from __future__ import with_statement

import os
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy.engine.url import URL

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# target_metadata = None
# parent_dir = os.path.abspath(os.path.join(os.getcwd(), ".."))
# sys.path.append(parent_dir)
import os, sys
sys.path.append(os.getcwd())
from models import Base
from settings import DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME

target_metadata = Base.metadata


# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url, compare_type=True)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""

alembic_config = config.get_section(config.config_ini_section)
alembic_config['sqlalchemy.url'] = URL(
drivername='postgresql',
username=DB_USER,
password=DB_PASSWORD,
host=DB_HOST,
port=DB_PORT,
database=DB_NAME
)

engine = engine_from_config(alembic_config)

with engine.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions alembic/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
39 changes: 39 additions & 0 deletions alembic/versions/20201121_1504_cee7a5698356_init_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Copyright Ⓒ 2020 "Sberbank Real Estate Center" Limited Liability Company. Licensed under the MIT license.
Please, see the LICENSE.md file in project's root for full licensing information.
"""
"""init_project
Revision ID: cee7a5698356
Revises:
Create Date: 2020-11-21 15:04:40.340403
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'cee7a5698356'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('student',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('active', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('student')
# ### end Alembic commands ###
4 changes: 4 additions & 0 deletions amqp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Copyright Ⓒ 2020 "Sberbank Real Estate Center" Limited Liability Company. Licensed under the MIT license.
Please, see the LICENSE.md file in project's root for full licensing information.
"""
22 changes: 22 additions & 0 deletions amqp/amqp_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Copyright Ⓒ 2020 "Sberbank Real Estate Center" Limited Liability Company. Licensed under the MIT license.
Please, see the LICENSE.md file in project's root for full licensing information.
"""
import settings


def get_app_config():
return dict(
connections=[
dict(
prefix='example',
params=dict(
host=settings.EXAMPLE_AMQP_HOST,
login=settings.EXAMPLE_AMQP_USER,
password=settings.EXAMPLE_AMQP_PASS,
virtualhost=settings.EXAMPLE_AMQP_VHOST,
port=int(settings.EXAMPLE_AMQP_PORT),
)
)
]
)
Loading

0 comments on commit 7012912

Please sign in to comment.