Skip to content

Commit

Permalink
fix: logging level, error to string, realtime url
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Jan 26, 2023
1 parent 774c75d commit 5df5719
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/serverless/worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ RUNPOD_WEBHOOK_POST_OUTPUT= # URL to post output to
RUNPOD_WEBHOOK_PING= # URL to ping
RUNPOD_PING_INTERVAL= # Interval in milliseconds to ping the API (Default: 10000)

RUNPOD_ENDPOINT_ID= # Endpoint ID

# Realtime
RUNPOD_REALTIME_PORT= # Port to listen on for realtime connections (Default: None)
RUNPOD_REALTIME_CONCURRENCY= # Number of workers to spawn (Default: 1)
Expand Down
2 changes: 1 addition & 1 deletion runpod/serverless/modules/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run_job(handler, job):
if isinstance(job_output, bool):
run_result = {"output": job_output}
elif "error" in job_output:
run_result = {"error": job_output['error']}
run_result = {"error": str(job_output['error'])}
else:
run_result = {"output": job_output}

Expand Down
20 changes: 17 additions & 3 deletions runpod/serverless/modules/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dotenv import load_dotenv

LOG_LEVEL_ERROR = 'ERROR '
LOG_LEVEL_WARN = 'WARNING'
LOG_LEVEL_WARN = 'WARN'
LOG_LEVEL_INFO = 'INFO '
LOG_LEVEL_DEBUG = 'DEBUG '

Expand All @@ -16,8 +16,22 @@ def log(message, level='INFO'):
'''
Log message to stdout if RUNPOD_DEBUG is true.
'''
if os.environ.get('RUNPOD_DEBUG', 'true') == 'true':
print(f'{level} | {message}', flush=True)
set_level = os.environ.get('RUNPOD_DEBUG_LEVEL', 'DEBUG').upper()

if os.environ.get('RUNPOD_DEBUG', 'False') != 'true':
return

if set_level == 'ERROR' and level != 'ERROR':
return

if set_level == 'WARN' and level not in ['ERROR', 'WARN']:
return

if set_level == 'INFO' and level not in ['ERROR', 'WARN', 'INFO']:
return

print(f'{level} | {message}', flush=True)
return


def log_secret(secret_name, secret, level='INFO'):
Expand Down
3 changes: 2 additions & 1 deletion runpod/serverless/modules/rp_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self):

self.config = {"handler": None}
self.rp_app = FastAPI()
self.rp_app.add_api_route("/run", self.run, methods=["POST"])
self.rp_app.add_api_route(f"{os.environ.get('RUNPOD_ENDPOINT_ID')}/realtime",
self.run, methods=["POST"])

def start_uvicorn(self, api_port):
'''
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = runpod
version = 0.8.0
version = 0.8.1
description = Official Python library for RunPod API & SDK.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 5df5719

Please sign in to comment.