Skip to content

Commit

Permalink
fix cache abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuejunior committed May 5, 2021
1 parent 6f0c140 commit 381124b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 1 addition & 4 deletions brandenburg/services/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from typing import Tuple

# Local application imports
from brandenburg.config import settings
from brandenburg import cache
from brandenburg.models.batch import BatchModel
from brandenburg.services.publisher import PublisherService
from brandenburg.toolbox._backends.redis import RedisBackend
from brandenburg.toolbox.logger import logger


Expand All @@ -34,8 +33,6 @@ async def upload(name: str, filename: str, file: bytes, hash: str, token: str) -
@classmethod
async def _set_last_ran(cls, batch: BatchModel) -> None:

# TODO: Convert the redis connection into a decorator
cache = await RedisBackend(settings.REDIS_URL).get_instance()
table: str = batch.table_name.lower()
updated_at: int = batch.last_updated_at
await cache.set_table_last_updated(table, updated_at)
8 changes: 4 additions & 4 deletions brandenburg/services/lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import asyncio # pragma: nocover
from typing import List, Tuple, Dict, Union

# Third party imports
from pydantic import ValidationError

# Local application imports
from brandenburg import cache
from brandenburg.models.lead import LeadModel
Expand All @@ -15,7 +12,10 @@
class LeadService:
@staticmethod
async def execute(token: str, lead: LeadModel) -> Union[bool, Tuple[Dict[str, Union[str, List[str]]], bool]]:

"""
TODO:
"""
#TODO: Improve the return type, to be more especific
is_valid: bool = await cache.is_valid_token(token)
if is_valid:
await logger.info(f"Is valid token with data")
Expand Down
2 changes: 1 addition & 1 deletion brandenburg/toolbox/_backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ async def set_table_last_updated(self, table: str, updated_at: int) -> None:
"""
last_updated_ts: int = max(int(await self._pool.get(key=table) or 0), updated_at)
await logger.info(f"Configuring last ran date to table: {table}, timestamp: {last_updated_ts}")
await cls.set(key=table, value=last_updated_ts)
await self._pool.set(table, last_updated_ts)
await logger.info("last ran was set successfully")
2 changes: 1 addition & 1 deletion brandenburg/toolbox/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def encode(data: Union[Dict[str, str], str, int]) -> str:
Can be a string, a dict or a integer and the function will return a encoded string
"""
if isinstance(data, dict):
return base64.b64encode(json.dumps(data).encode()).decode()
return base64.b64encode(json.dumps(data)).decode()
else:
return base64.b64encode(str(data).encode()).decode()

Expand Down

0 comments on commit 381124b

Please sign in to comment.