Skip to content

Commit

Permalink
WIP Windows #89
Browse files Browse the repository at this point in the history
  • Loading branch information
AliRn76 committed Apr 8, 2024
2 parents e690935 + efcfd4a commit 005f37c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion panther/__init__.py
@@ -1,6 +1,6 @@
from panther.main import Panther # noqa: F401

__version__ = '4.1.1'
__version__ = '4.1.2'


def version():
Expand Down
2 changes: 1 addition & 1 deletion panther/_utils.py
Expand Up @@ -82,7 +82,7 @@ def clean_traceback_message(exception: Exception) -> str:
tb = TracebackException(type(exception), exception, exception.__traceback__)
stack = tb.stack.copy()
for t in stack:
if t.filename.find('site-packages/panther') != -1:
if t.filename.find('site-packages/panther') != -1 or t.filename.find('site-packages\\panther') != -1:
tb.stack.remove(t)
_traceback = list(tb.format(chain=False))
return exception if len(_traceback) == 1 else f'{exception}\n' + ''.join(_traceback)
Expand Down
7 changes: 5 additions & 2 deletions panther/base_websocket.py
Expand Up @@ -52,8 +52,11 @@ async def __call__(self):
queue = self.pubsub.subscribe()
logger.info("Subscribed to 'websocket_connections' queue")
while True:
received_message = queue.get()
await self._handle_received_message(received_message=received_message)
try:
received_message = queue.get()
await self._handle_received_message(received_message=received_message)
except InterruptedError:
break
else:
# We have a redis connection, so use it for pubsub
self.pubsub = self.pubsub_connection.pubsub()
Expand Down
2 changes: 1 addition & 1 deletion panther/cli/monitor_command.py
Expand Up @@ -57,7 +57,7 @@ def initialize(self) -> str:

# Check log file
if not self.monitoring_log_file.exists():
return f'`{self.monitoring_log_file}` file not found. (Make sure `MONITORING` is `True` in `configs`'
return f'`{self.monitoring_log_file}` file not found. (Make sure `MONITORING` is `True` in `configs` and you have at least one record)'

# Initialize Deque
self.update_rows()
Expand Down
4 changes: 3 additions & 1 deletion panther/cli/run_command.py
@@ -1,3 +1,4 @@
import contextlib
import os

import uvicorn
Expand Down Expand Up @@ -75,6 +76,7 @@ def run(args: list[str]) -> None:
command.update(_handle_commands(args))
command.update(args)
try:
uvicorn.run('main:app', **command)
with contextlib.suppress(KeyboardInterrupt):
uvicorn.run('main:app', **command)
except TypeError as e:
cli_error(e)
8 changes: 7 additions & 1 deletion panther/db/connections.py
Expand Up @@ -122,7 +122,13 @@ def __init__(
def sync_ping(self):
from redis import Redis

Redis(host=self.host, port=self.port, **self.kwargs).ping()
Redis(host=self.host, port=self.port, socket_timeout=3, **self.kwargs).ping()

async def execute_command(self, *args, **options):
if self.is_connected:
return await super().execute_command(*args, **options)
msg = '`REDIS` is not found in `configs`'
raise ValueError(msg)

def create_connection_for_websocket(self) -> _Redis:
if not hasattr(self, 'websocket_connection'):
Expand Down
2 changes: 1 addition & 1 deletion panther/db/models.py
Expand Up @@ -58,7 +58,7 @@ async def update_last_login(self) -> None:

async def login(self) -> dict:
"""Return dict of access and refresh token"""
return config.AUTHENTICATION.login(self.id)
return config.AUTHENTICATION.login(str(self.id))

async def logout(self) -> dict:
return await config.AUTHENTICATION.logout(self._auth_token)
Expand Down
4 changes: 2 additions & 2 deletions panther/logging.py
Expand Up @@ -66,8 +66,8 @@ def __init__(self, filename, mode='a', encoding=None, delay=False, errors=None):
},
'uvicorn.error': {
'handlers': ['default'],
'level': 'WARNING',
'level': 'INFO',
'propagate': False,
},
}
}
}

0 comments on commit 005f37c

Please sign in to comment.