Skip to content

Commit

Permalink
Revert "Feature/remove rest client from celery (#730)" (#734)
Browse files Browse the repository at this point in the history
This reverts commit 8e42c7d.
  • Loading branch information
helllllllder committed Jul 26, 2022
1 parent 94fcdc2 commit cb5c3e8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
23 changes: 8 additions & 15 deletions bothub/api/v2/internal/connect_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import List, Dict

from django.conf import settings
from django.core.cache import cache


class ConnectRESTClient:
Expand All @@ -28,21 +27,15 @@ def get_auth_token(self) -> str:
def list_classifiers(
self, project_uuid: str, user_email: str
) -> List[Dict[str, str]]:
cache_key = f"LIST_CLASSIFIER_CACHE_KEY:project_uuid:{project_uuid}:user_email:{user_email}"
cache_result = cache.get(cache_key, None)
if cache_result is None:
request = requests.get(
url=f"{self.base_url}/v1/organization/project/list_classifier/",
headers=self.headers,
params={"project_uuid": project_uuid, "user_email": user_email},
)
cache.set(cache_key, request.json().get("data"), settings.CACHE_TTL)
return request.json().get("data")
else:
return cache_result
request = requests.get(
url=f"{self.base_url}/v1/organization/project/list_classifier/",
headers=self.headers,
params={"project_uuid": project_uuid, "user_email": user_email},
)

def list_authorizations(self, project_uuid: str, user_email: str) -> List[str]:
return request.json()["data"]

def list_authorizations(self, project_uuid: str, user_email: str) -> List[str]:
classifiers = self.list_classifiers(
project_uuid=project_uuid, user_email=user_email
)
Expand All @@ -53,7 +46,7 @@ def get_authorization_classifier(
self, project_uuid: str, authorization_uuid: str, user_email: str
) -> str:
"""
Receives a authorization UUID and returns the respective classifier UUID
Recives a authorization UUID and returns the respective classifier UUID
"""
classifiers = self.list_classifiers(project_uuid, user_email)
classifier = filter(
Expand Down
2 changes: 0 additions & 2 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,3 @@
]

REPOSITORY_BLOCK_USER_LOGS = env.list("REPOSITORY_BLOCK_USER_LOGS", default=[])

CACHE_TTL = env.int("CACHE_TTL", default=180)

0 comments on commit cb5c3e8

Please sign in to comment.