Skip to content

Commit 100906d

Browse files
authored
Merge pull request #5 from therealadityashankar/main
added RUNPOD_REQUEST_TIMEOUT, to env - to allow for more control over the timeout for the user
2 parents f99fc69 + f6bed30 commit 100906d

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ARG COG_VERSION
44

55
FROM r8.im/${COG_REPO}/${COG_MODEL}@sha256:${COG_VERSION}
66

7+
ENV RUNPOD_REQUEST_TIMEOUT=600
8+
79
# Install necessary packages and Python 3.10
810
RUN apt-get update && apt-get upgrade -y && \
911
apt-get install -y --no-install-recommends software-properties-common curl git openssh-server && \
@@ -21,4 +23,4 @@ RUN /opt/venv/bin/pip install runpod
2123

2224
ADD src/handler.py /rp_handler.py
2325

24-
CMD ["/opt/venv/bin/python3", "-u", "/rp_handler.py"]
26+
CMD ["/opt/venv/bin/python3", "-u", "/rp_handler.py"]

src/handler.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import time
22
import subprocess
3+
import os
34

45
import runpod
56
import requests
67
from requests.adapters import HTTPAdapter, Retry
78

9+
TIMEOUT = int(os.environ.get("RUNPOD_REQUEST_TIMEOUT", "600"))
10+
811
LOCAL_URL = "http://127.0.0.1:5000"
912

1013
cog_session = requests.Session()
@@ -46,13 +49,14 @@ def run_inference(inference_request):
4649
Run inference on a request.
4750
'''
4851
response = cog_session.post(url=f'{LOCAL_URL}/predictions',
49-
json=inference_request, timeout=600)
52+
json=inference_request, timeout=TIMEOUT)
53+
54+
if response.status_code != 200:
55+
print("Request failed - reason :", response.status_code, response.text)
56+
5057
return response.json()
5158

5259

53-
# ---------------------------------------------------------------------------- #
54-
# RunPod Handler #
55-
# ---------------------------------------------------------------------------- #
5660
def handler(event):
5761
'''
5862
This is the handler function that will be called by the serverless.
@@ -68,4 +72,4 @@ def handler(event):
6872

6973
print("Cog API Service is ready. Starting RunPod serverless handler...")
7074

71-
runpod.serverless.start({"handler": handler})
75+
runpod.serverless.start({"handler": handler})

0 commit comments

Comments
 (0)