Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring cleanup (and MetricQ 5) #18

Merged
merged 13 commits into from
Mar 15, 2024
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,165 @@ VENV

# created by setuptools_scm
metricq_sink_websocket/version.py


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/metricq/metricq-python:v4.2 AS BUILDER
FROM ghcr.io/metricq/metricq-python:v5.3 AS BUILDER

USER root
RUN apt-get update \
Expand All @@ -12,10 +12,10 @@ COPY --chown=metricq:metricq . /home/metricq/metricq_sink_websocket
USER metricq
WORKDIR /home/metricq/metricq_sink_websocket

RUN pip install --user . uvloop
RUN pip install --user '.[uvloop]'


FROM ghcr.io/metricq/metricq-python:v4.2
FROM ghcr.io/metricq/metricq-python:v5.3

COPY --from=BUILDER --chown=metricq:metricq /home/metricq/.local /home/metricq/.local

Expand Down
2 changes: 2 additions & 0 deletions metricq_sink_websocket/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .main import runserver_cmd

__all__ = ["runserver_cmd"]
31 changes: 16 additions & 15 deletions metricq_sink_websocket/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import asyncio
import logging
import traceback
import sys

import asyncio
import aiohttp_cors # type: ignore
import click
import click_completion
import click_log

import click_completion # type: ignore
import click_log # type: ignore
from aiohttp import web
import aiohttp_cors

from metricq import get_logger

from .routes import setup_routes
Expand All @@ -27,7 +24,7 @@
click_completion.init()


async def metricq_disconnect_handler(app):
async def metricq_disconnect_handler(app: web.Application) -> None:
logger.info("MetricQ is running...")

try:
Expand All @@ -44,7 +41,7 @@ async def metricq_disconnect_handler(app):
sys.exit(2)


async def start_background_tasks(app):
async def start_background_tasks(app: web.Application) -> None:
app["sink"] = Sink(
app["token"],
app["management_url"],
Expand All @@ -56,11 +53,13 @@ async def start_background_tasks(app):
asyncio.create_task(metricq_disconnect_handler(app))


async def cleanup_background_tasks(app):
async def cleanup_background_tasks(app: web.Application) -> None:
pass


def create_app(token, management_url, management_exchange, port):
def create_app(
token: str, management_url: str, management_exchange: str, port: int
tilsche marked this conversation as resolved.
Show resolved Hide resolved
) -> web.Application:
app = web.Application()
app["token"] = token
app["management_url"] = management_url
Expand Down Expand Up @@ -89,12 +88,14 @@ def create_app(token, management_url, management_exchange, port):
@click.option("--token", default="metricq-sink-websocket")
@click.option("--management-exchange", default="metricq.management")
tilsche marked this conversation as resolved.
Show resolved Hide resolved
@click.option("--host", default="0.0.0.0")
@click.option("--port", default="3000")
@click.option("--port", type=int, default=3000)
@click.version_option(client_version)
@click_log.simple_verbosity_option(logger)
def runserver_cmd(management_url, token, management_exchange, host, port):
@click_log.simple_verbosity_option(logger) # type: ignore
def runserver_cmd(
management_url: str, token: str, management_exchange: str, host: str, port: int
) -> None:
try:
import uvloop
import uvloop # type: ignore

uvloop.install()
logger.info("using uvloop as event loop")
Expand Down
6 changes: 5 additions & 1 deletion metricq_sink_websocket/routes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Module for route setup"""

import aiohttp_cors # type: ignore
from aiohttp import web

from .views import websocket_handler


def setup_routes(app, cors):
def setup_routes(app: web.Application, cors: aiohttp_cors.CorsConfig) -> None:
"""Setup routes and cors for app."""
resource = cors.add(app.router.add_resource("/"))
cors.add(resource.add_route("GET", websocket_handler))
Loading
Loading