Skip to content

Commit

Permalink
Issue #34 - use explicit asyncio loop for app
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Nov 18, 2024
1 parent 5a26d74 commit 2b34567
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ repos:
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/akaihola/darglint2
rev: v1.8.2
hooks:
- id: darglint2
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand All @@ -16,7 +12,7 @@ repos:
rev: 7.1.1
hooks:
- id: flake8
args: ["--ignore=E203,S301,S403,W503,C901", --darglint-ignore-regex, .*]
args: ["--ignore=E203,S301,S403,W503,C901"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Running Locally

.. code:: console
$ flask --app dm_mac run
$ mac-server --debug
The app will now be available at http://127.0.0.1:5000

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [

[tool.poetry.scripts]
neongetter = "dm_mac.neongetter:main"
mac-server = "dm_mac:main"

[tool.poetry.urls]
Changelog = "https://github.com/jantman/machine_access_control/releases"
Expand Down
23 changes: 23 additions & 0 deletions src/dm_mac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Decatur Makers Machine Access Control."""

import argparse
import asyncio
import logging
import sys
from time import time

from quart import Quart
Expand Down Expand Up @@ -61,3 +64,23 @@ def create_app() -> Quart:
app.register_blueprint(api)
app.add_url_rule("/metrics", view_func=prometheus_route)
return app


def main() -> None:
p = argparse.ArgumentParser(description="Run Machine Access Control (MAC) server")
p.add_argument(
"-d",
"--debug",
dest="debug",
action="store_true",
default=False,
help="Debug mode",
)
args = p.parse_args(sys.argv[1:])
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
app: Quart = create_app()
app.run(loop=loop, debug=args.debug, host="0.0.0.0")


if __name__ == "__main__":
main()

0 comments on commit 2b34567

Please sign in to comment.