|
15 | 15 | from infrahub.git.repository import get_initialized_repo |
16 | 16 | from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow |
17 | 17 | from infrahub.trigger.models import TriggerSetupReport, TriggerType |
18 | | -from infrahub.trigger.setup import setup_triggers |
| 18 | +from infrahub.trigger.setup import setup_triggers, setup_triggers_specific |
19 | 19 | from infrahub.workflows.catalogue import ( |
20 | 20 | COMPUTED_ATTRIBUTE_PROCESS_JINJA2, |
21 | 21 | COMPUTED_ATTRIBUTE_PROCESS_TRANSFORM, |
@@ -304,36 +304,30 @@ async def computed_attribute_setup_jinja2( |
304 | 304 | await add_tags(branches=[branch_name]) |
305 | 305 | await wait_for_schema_to_converge(branch_name=branch_name, component=service.component, db=db, log=log) |
306 | 306 |
|
307 | | - triggers = await gather_trigger_computed_attribute_jinja2() |
308 | | - |
| 307 | + report: TriggerSetupReport = await setup_triggers_specific( |
| 308 | + gatherer=gather_trigger_computed_attribute_jinja2, trigger_type=TriggerType.COMPUTED_ATTR_JINJA2 |
| 309 | + ) # type: ignore[misc] |
309 | 310 | # Configure all ComputedAttrJinja2Trigger in Prefect |
310 | | - async with get_client(sync_client=False) as prefect_client: |
311 | | - report: TriggerSetupReport = await setup_triggers( |
312 | | - client=prefect_client, |
313 | | - triggers=triggers, |
314 | | - trigger_type=TriggerType.COMPUTED_ATTR_JINJA2, |
315 | | - force_update=False, |
316 | | - ) # type: ignore[misc] |
317 | 311 |
|
318 | | - # Since we can have multiple trigger per NodeKind |
319 | | - # we need to extract the list of unique node that should be processed |
320 | | - unique_nodes: set[tuple[str, str, str]] = { |
321 | | - (trigger.branch, trigger.computed_attribute.kind, trigger.computed_attribute.attribute.name) # type: ignore[attr-defined] |
322 | | - for trigger in report.updated + report.created |
323 | | - } |
324 | | - for branch, kind, attribute_name in unique_nodes: |
325 | | - if event_name != BranchDeletedEvent.event_name and branch == branch_name: |
326 | | - await service.workflow.submit_workflow( |
327 | | - workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES, |
328 | | - context=context, |
329 | | - parameters={ |
330 | | - "branch_name": branch, |
331 | | - "computed_attribute_name": attribute_name, |
332 | | - "computed_attribute_kind": kind, |
333 | | - }, |
334 | | - ) |
335 | | - |
336 | | - log.info(f"{len(triggers)} Computed Attribute for Jinja2 automation configuration completed") |
| 312 | + # Since we can have multiple trigger per NodeKind |
| 313 | + # we need to extract the list of unique node that should be processed |
| 314 | + unique_nodes: set[tuple[str, str, str]] = { |
| 315 | + (trigger.branch, trigger.computed_attribute.kind, trigger.computed_attribute.attribute.name) # type: ignore[attr-defined] |
| 316 | + for trigger in report.updated + report.created |
| 317 | + } |
| 318 | + for branch, kind, attribute_name in unique_nodes: |
| 319 | + if event_name != BranchDeletedEvent.event_name and branch == branch_name: |
| 320 | + await service.workflow.submit_workflow( |
| 321 | + workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES, |
| 322 | + context=context, |
| 323 | + parameters={ |
| 324 | + "branch_name": branch, |
| 325 | + "computed_attribute_name": attribute_name, |
| 326 | + "computed_attribute_kind": kind, |
| 327 | + }, |
| 328 | + ) |
| 329 | + |
| 330 | + log.info(f"{report.in_use_count} Computed Attribute for Jinja2 automation configuration completed") |
337 | 331 |
|
338 | 332 |
|
339 | 333 | @flow( |
|
0 commit comments