Skip to content

Commit

Permalink
make number of threads configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Nov 23, 2023
1 parent d2fcd8b commit d5c29e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dsp_permissions_scripts/oap/oap_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ def _launch_thread_pool(
resource_oaps: list[Oap],
host: str,
token: str,
nthreads: int,
) -> list[str]:
counter = 0
total = len(resource_oaps)
failed_res_iris: list[str] = []
with ThreadPoolExecutor(max_workers=4) as pool:
with ThreadPoolExecutor(max_workers=nthreads) as pool:
jobs = [
pool.submit(
_update_permissions_for_resource_and_values,
Expand Down Expand Up @@ -213,16 +214,20 @@ def apply_updated_oaps_on_server(
host: str,
token: str,
shortcode: str,
nthreads: int = 4,
) -> None:
"""Applies modified Object Access Permissions of resources (and their values) on a DSP server."""
"""
Applies modified Object Access Permissions of resources (and their values) on a DSP server.
Don't forget to set a number of threads that doesn't overload the server.
"""
if not resource_oaps:
logger.warning(f"There are no OAPs to update on {host}")
warnings.warn(f"There are no OAPs to update on {host}")
return
logger.info(f"******* Updating OAPs of {len(resource_oaps)} resources on {host} *******")
print(f"******* Updating OAPs of {len(resource_oaps)} resources on {host} *******")

failed_res_iris = _launch_thread_pool(resource_oaps, host, token)
failed_res_iris = _launch_thread_pool(resource_oaps, host, token, nthreads)

if failed_res_iris:
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
Expand Down
1 change: 1 addition & 0 deletions dsp_permissions_scripts/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def update_oaps(
host=host,
token=token,
shortcode=shortcode,
nthreads=4,
)
resource_oaps_updated = get_all_resource_oaps_of_project(
shortcode=shortcode,
Expand Down

0 comments on commit d5c29e4

Please sign in to comment.