Skip to content

Commit

Permalink
Merge pull request #2415 from IFRCGo/develop
Browse files Browse the repository at this point in the history
ERP_API_MAX_REQ_TIMEOUT to 1 min
  • Loading branch information
szabozoltan69 authored Feb 18, 2025
2 parents 5138391 + ca851f6 commit 939a4cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ jobs:
run: |
BRANCH_NAME=$(echo $GITHUB_REF_NAME | sed 's|:|-|' | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g' | cut -c1-100 | sed 's/-*$//')
# NOTE: `c` is to avoid error by helm if GITHUB_SHA[:7] has only numbers
GIT_HASH="c$(echo $GITHUB_SHA | head -c7)"
# XXX: Check if there is a slash in the BRANCH_NAME eg: project/add-docker
if [[ "$BRANCH_NAME" == *"/"* ]]; then
# XXX: Change the docker image package to -alpha
IMAGE_NAME="$IMAGE_NAME-alpha"
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GITHUB_SHA | head -c7)"
TAG="$(echo "$BRANCH_NAME" | sed 's|/|-|g').$(echo $GIT_HASH)"
else
TAG="$BRANCH_NAME.$(echo $GITHUB_SHA | head -c7)"
TAG="$BRANCH_NAME.$(echo $GIT_HASH)"
fi
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[:upper:]' '[:lower:]')
Expand Down
2 changes: 1 addition & 1 deletion main/mock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import Mock


def erp_request_side_effect_mock(url, json, headers):
def erp_request_side_effect_mock(url, json, headers, timeout):
def _generate_mock(status_code, json, headers):
response_mock = Mock()
response_mock.text = "FindThisGUID"
Expand Down
1 change: 1 addition & 0 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ def log_render_extra_context(record):

ERP_API_ENDPOINT = env("ERP_API_ENDPOINT")
ERP_API_SUBSCRIPTION_KEY = env("ERP_API_SUBSCRIPTION_KEY")
ERP_API_MAX_REQ_TIMEOUT = 60 # 1 minutes

TEST_DIR = os.path.join(BASE_DIR, "main/test_files")

Expand Down
25 changes: 23 additions & 2 deletions utils/erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

from api.logger import logger
from api.models import ERPGUID, RequestChoices
from main.utils import logger_context

ERP_API_ENDPOINT = settings.ERP_API_ENDPOINT
ERP_API_SUBSCRIPTION_KEY = settings.ERP_API_SUBSCRIPTION_KEY
ERP_API_MAX_REQ_TIMEOUT = settings.ERP_API_MAX_REQ_TIMEOUT


def push_fr_data(data, retired=False):
Expand Down Expand Up @@ -119,8 +121,27 @@ def push_fr_data(data, retired=False):
"Ocp-Apim-Trace": "true",
"Ocp-Apim-Subscription-Key": ERP_API_SUBSCRIPTION_KEY,
}
# The response contains the GUID (res.text)
res = requests.post(ERP_API_ENDPOINT, json=payload, headers=headers)

# NOTE: Change this to an asynchronous call
try:
# The response contains the GUID (res.text)
res = requests.post(ERP_API_ENDPOINT, json=payload, headers=headers, timeout=ERP_API_MAX_REQ_TIMEOUT)
except requests.exceptions.Timeout:
error_context = logger_context(
{
"field_report_id": data.id,
"url": ERP_API_ENDPOINT,
"payload": payload,
"content": res.content,
"headers": headers,
"status_code": res.status_code,
}
)
logger.error(
"Request to ERP API timed out.",
exc_info=True,
extra=error_context,
)

if res.status_code == 200:
res_text = res.text.replace('"', "")
Expand Down

0 comments on commit 939a4cd

Please sign in to comment.