Skip to content

Commit

Permalink
Default max concurrency to 5 connections. See https://developer.jamf.…
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz00 committed Jun 30, 2024
1 parent d3ea413 commit f5d2c4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def animate_search(stop_event: threading.Event, enable_animation: bool) -> None:
is_flag=True,
help="Include the amount of enrolled mobile devices on the latest version of their respective OS.",
)
@click.option("--concurrency", type=click.INT, default=5, help="Set the maximum concurrency level for API calls.")
@click.option(
"--debug",
"-x",
Expand All @@ -92,8 +93,9 @@ async def main(
pdf: bool,
sort: Optional[AnyStr],
omit: bool,
ios: bool,
date_format: AnyStr,
ios: bool,
concurrency: int,
debug: bool,
) -> None:
config = ConfigManager()
Expand All @@ -102,6 +104,8 @@ async def main(
excel_report = ExcelReport(config)
ui_config = UIConfigManager()
pdf_report = PDFReport(ui_config)
api_client.jamf_client.set_max_concurrency(concurrency=concurrency)

patcher = Patcher(
config, token_manager, api_client, excel_report, pdf_report, ui_config, debug
)
Expand Down
21 changes: 21 additions & 0 deletions src/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from pydantic import BaseModel, field_validator, Field
from urllib.parse import urlparse, urlunparse
from typing import Optional, AnyStr
from src import logger

logthis = logger.setup_child_logger("models", __name__)


class AccessToken(BaseModel):
Expand Down Expand Up @@ -61,12 +64,16 @@ class JamfClient(BaseModel):
:type server: AnyStr
:param token: The access token for the Jamf client.
:type token: Optional[AccessToken]
:param max_concurrency: The maximum concurrency level for API calls.
Defaults to 5 per Jamf Developer documentation.
:type max_concurrency: int
"""

client_id: AnyStr
client_secret: AnyStr
server: AnyStr
token: Optional[AccessToken] = None
max_concurrency: int = 5

@staticmethod
def valid_url(url: AnyStr) -> AnyStr:
Expand Down Expand Up @@ -127,3 +134,17 @@ def base_url(self):
:rtype: AnyStr
"""
return self.server

def set_max_concurrency(self, concurrency: int):
"""
Sets the maximum concurrency level for API calls. It is **strongly
recommended** to limit API call concurrency to no more than 5 connections.
See https://developer.jamf.com/developer-guide/docs/jamf-pro-api-scalability-best-practices
:param concurrency: The new maximum concurrency level.
:type concurrency: int
"""
if concurrency < 1:
logthis.error("Concurrency level must be at least 1!")
raise ValueError("Concurrency level must be at least 1. ")
self.max_concurrency = concurrency

0 comments on commit f5d2c4c

Please # to comment.