Skip to content

Commit

Permalink
Feature/remove rest client from celery (#730)
Browse files Browse the repository at this point in the history
* Develop (#709) (#710)

* Fix: Remove ai from project (#707)

* remove document deletion from delete_nlp_logs task

* inconsistency number and debug errors fixed

* add user_email to remove_authorizations_project

* Feature/health check blocklist (#708)

* remove document deletion from delete_nlp_logs task

* add a blocklist for not saving logs depending on the authorization user

* inconsistency number and debug errors fixed

* change the REPOSITORY_BLOCK_USER_LOGS values from users to repository authorizations

* change readme

* pass on sonarcloud

* change admins settings

* transform uuid into string

* convert uuid into string at test_blocked_user

* feat: update list_project_organization endpoint removing the celery call

* feat: update all code that called celery tasks for communicating with connect to calls directly into ConnectRESTClient

* bugfix: remove task.result after condition to user or not grpc endpoints, as it was conflicting with the rest call

* feat: cache request result in list_classifiers
  • Loading branch information
helllllllder committed Jul 21, 2022
1 parent e54bdc0 commit 8e42c7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 15 additions & 8 deletions bothub/api/v2/internal/connect_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Dict

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


class ConnectRESTClient:
Expand All @@ -27,15 +28,21 @@ def get_auth_token(self) -> str:
def list_classifiers(
self, project_uuid: str, user_email: str
) -> List[Dict[str, str]]:
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},
)

return request.json()["data"]
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

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

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

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

0 comments on commit 8e42c7d

Please sign in to comment.