Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control worker timeout #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading