Skip to content

Commit

Permalink
fix pydantic/_thread.lock interaction errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Szefler committed Dec 4, 2023
1 parent 112e68b commit 9286ed6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/robusta/core/playbooks/base_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ def get_event_description(self) -> str:


class BaseTrigger(DocumentedModel):
# TODO what should the pool size be?
executor = ProcessPoolExecutor(max_workers=1)
def __new__(cls, *args, **kwargs):
# Perform any pydantic-related class building code before creating the
# executor. Otherwise obscure errors related to pickling _thread.lock ensue.
cls = super().__new__(cls)
# TODO what should the pool size be?
cls._executor = ProcessPoolExecutor(max_workers=1)

def get_trigger_event(self) -> str:
pass
Expand All @@ -33,7 +37,7 @@ def should_fire(self, event: TriggerEvent, playbook_id: str):
def build_execution_event(
self, event: TriggerEvent, sink_findings: Dict[str, List[Finding]]
) -> Optional[ExecutionBaseEvent]:
return BaseTrigger.executor.submit(self._build_execution_event, event, sink_findings)
return BaseTrigger._executor.submit(self._build_execution_event, event, sink_findings)

def _build_execution_event(
self, event: TriggerEvent, sink_findings: Dict[str, List[Finding]]
Expand Down

0 comments on commit 9286ed6

Please sign in to comment.