diff --git a/README.md b/README.md index 682e535..c2dec66 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,13 @@ worker threads using the following commands: The Redis server can be controlled through the environment variable `REDIS_URL` which defaults to `redis://localhost:6379` +Time to live and timeout of the workers can be controlled with the following environment variables + +| Name | Description | +| -------------- | ------------------------------------------- | +| REDIS_TTL | Time to keep results in redis (default=500) | +| WORKER_TIMEOUT | Timeout in seconds (default=180) | + # Use [CORS](https://flask-cors.readthedocs.io/en/latest/index.html) The API server supports exposing its functionality to other origins than its own. @@ -92,13 +99,12 @@ The static API key is configured by the environment variable `AUTH_API_KEY` Keycloak is configured using the following environement variables - -|Name |Description | -|-------------------|-----------------------------------| -|AUTH_SERVER |Base url of your Keycloak server | -|AUTH_REALM_NAME |OAuth realm name | -|AUTH_CLIENT_ID |Client ID | -|AUTH_CLIENT_SECRET |Client secret | +| Name | Description | +| ------------------ | -------------------------------- | +| AUTH_SERVER | Base url of your Keycloak server | +| AUTH_REALM_NAME | OAuth realm name | +| AUTH_CLIENT_ID | Client ID | +| AUTH_CLIENT_SECRET | Client secret | # Adding or updating dependencies diff --git a/optimizerapi/optimizer.py b/optimizerapi/optimizer.py index 633778e..32cd54b 100644 --- a/optimizerapi/optimizer.py +++ b/optimizerapi/optimizer.py @@ -43,6 +43,10 @@ TTL = int(os.environ["REDIS_TTL"]) else: TTL = 500 +if "WORKER_TIMEOUT" in os.environ: + WORKER_TIMEOUT = int(os.environ["WORKER_TIMEOUT"]) +else: + WORKER_TIMEOUT = 180 plt.switch_backend("Agg") @@ -77,7 +81,7 @@ def disconnect_check(): print("Found existing job") except NoSuchJobError: print("Creating new job") - job = queue.enqueue(do_run_work, body, job_id=job_id, result_ttl=TTL) + job = queue.enqueue(do_run_work, body, job_id=job_id, result_ttl=TTL, timeout=WORKER_TIMEOUT) while job.return_value is None: if disconnect_check(): try: