Skip to content
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
1 change: 1 addition & 0 deletions changelog/+default-max-concurrent-execution.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The default number of batch tasks that run at the same time, 5, is now available as `DEFAULT_MAX_CONCURRENT_EXECUTION` in `infrahub_sdk.constants`. `InfrahubBatch`, `InfrahubBatchSync` and `Config` use it as their default, so code that receives an optional concurrency value can pass `DEFAULT_MAX_CONCURRENT_EXECUTION` when the value is `None` instead of repeating the number 5.
8 changes: 6 additions & 2 deletions infrahub_sdk/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any

from .constants import DEFAULT_MAX_CONCURRENT_EXECUTION
Comment thread
saltas888 marked this conversation as resolved.
Resolved

if TYPE_CHECKING:
from .node import InfrahubNode, InfrahubNodeSync

Expand Down Expand Up @@ -56,7 +58,7 @@ class InfrahubBatch:
def __init__(
self,
semaphore: asyncio.Semaphore | None = None,
max_concurrent_execution: int = 5,
max_concurrent_execution: int = DEFAULT_MAX_CONCURRENT_EXECUTION,
return_exceptions: bool = False,
) -> None:
self._tasks: list[BatchTask] = []
Expand Down Expand Up @@ -88,7 +90,9 @@ async def execute(self) -> AsyncGenerator:


class InfrahubBatchSync:
def __init__(self, max_concurrent_execution: int = 5, return_exceptions: bool = False) -> None:
def __init__(
self, max_concurrent_execution: int = DEFAULT_MAX_CONCURRENT_EXECUTION, return_exceptions: bool = False
) -> None:
self._tasks: list[BatchTaskSync] = []
self.max_concurrent_execution = max_concurrent_execution
self.return_exceptions = return_exceptions
Expand Down
6 changes: 4 additions & 2 deletions infrahub_sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pydantic_settings import BaseSettings, InitSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict
from typing_extensions import Self

from .constants import InfrahubClientMode, Priority
from .constants import DEFAULT_MAX_CONCURRENT_EXECUTION, InfrahubClientMode, Priority
from .playback import JSONPlayback
from .recorder import JSONRecorder, NoRecorder, Recorder, RecorderType
from .types import AsyncRequester, InfrahubLoggers, RequesterTransport, SyncRequester
Expand Down Expand Up @@ -54,7 +54,9 @@ class ConfigBase(BaseSettings):
)
identifier: str | None = Field(default=None, description="Tracker identifier")
insert_tracker: bool = Field(default=False, description="Insert a tracker on queries to the server")
max_concurrent_execution: int = Field(default=5, description="Max concurrent execution in batch mode")
max_concurrent_execution: int = Field(
default=DEFAULT_MAX_CONCURRENT_EXECUTION, description="Max concurrent execution in batch mode"
)
mode: InfrahubClientMode = Field(default=InfrahubClientMode.DEFAULT, description="Default mode for the client")
pagination_size: int = Field(default=50, description="Page size for queries to the server")
priority: Priority | None = Field(
Expand Down
4 changes: 3 additions & 1 deletion infrahub_sdk/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Enumerations shared across the Infrahub SDK."""
"""Enumerations and constants shared across the Infrahub SDK."""

import enum

DEFAULT_MAX_CONCURRENT_EXECUTION = 5
Comment thread
saltas888 marked this conversation as resolved.
Resolved


class InfrahubClientMode(str, enum.Enum):
DEFAULT = "default"
Expand Down