Skip to content

Commit

Permalink
Control worker timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
langdal committed Apr 23, 2024
1 parent 0277479 commit d409469
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion optimizerapi/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d409469

Please sign in to comment.