|
14 | 14 | from infrahub.events import BranchDeletedEvent |
15 | 15 | from infrahub.git.repository import get_initialized_repo |
16 | 16 | from infrahub.services import InfrahubServices # noqa: TC001 needed for prefect flow |
17 | | -from infrahub.trigger.models import TriggerType |
| 17 | +from infrahub.trigger.models import TriggerSetupReport, TriggerType |
18 | 18 | from infrahub.trigger.setup import setup_triggers |
19 | 19 | from infrahub.workflows.catalogue import ( |
20 | 20 | COMPUTED_ATTRIBUTE_PROCESS_JINJA2, |
|
25 | 25 | from infrahub.workflows.utils import add_tags, wait_for_schema_to_converge |
26 | 26 |
|
27 | 27 | from .gather import gather_trigger_computed_attribute_jinja2, gather_trigger_computed_attribute_python |
28 | | -from .models import ComputedAttrJinja2GraphQL, ComputedAttrJinja2GraphQLResponse, PythonTransformTarget |
| 28 | +from .models import ( |
| 29 | + ComputedAttrJinja2GraphQL, |
| 30 | + ComputedAttrJinja2GraphQLResponse, |
| 31 | + PythonTransformTarget, |
| 32 | +) |
29 | 33 |
|
30 | 34 | if TYPE_CHECKING: |
31 | 35 | from infrahub.core.schema.computed_attribute import ComputedAttribute |
@@ -159,10 +163,10 @@ async def trigger_update_python_computed_attributes( |
159 | 163 |
|
160 | 164 |
|
161 | 165 | @flow( |
162 | | - name="process_computed_attribute_value_jinja2", |
163 | | - flow_run_name="Update value for computed attribute {attribute_name}", |
| 166 | + name="computed-attribute-jinja2-update-value", |
| 167 | + flow_run_name="Update value for computed attribute {node_kind}:{attribute_name}", |
164 | 168 | ) |
165 | | -async def update_computed_attribute_value_jinja2( |
| 169 | +async def computed_attribute_jinja2_update_value( |
166 | 170 | branch_name: str, |
167 | 171 | obj: ComputedAttrJinja2GraphQLResponse, |
168 | 172 | node_kind: str, |
@@ -246,7 +250,7 @@ async def process_jinja2( |
246 | 250 | batch = await service.client.create_batch() |
247 | 251 | for node in found: |
248 | 252 | batch.add( |
249 | | - task=update_computed_attribute_value_jinja2, |
| 253 | + task=computed_attribute_jinja2_update_value, |
250 | 254 | branch_name=branch_name, |
251 | 255 | obj=node, |
252 | 256 | node_kind=node_schema.kind, |
@@ -302,36 +306,33 @@ async def computed_attribute_setup_jinja2( |
302 | 306 |
|
303 | 307 | triggers = await gather_trigger_computed_attribute_jinja2() |
304 | 308 |
|
305 | | - # Since we can have multiple trigger per NodeKind |
306 | | - # we need to extract the list of unique node that should be processed |
307 | | - # also |
308 | | - # Because the automation in Prefect doesn't capture all information about the computed attribute |
309 | | - # we can't tell right now if a given computed attribute has changed and need to be updated |
310 | | - unique_nodes: set[tuple[str, str, str]] = { |
311 | | - (trigger.branch, trigger.computed_attribute.kind, trigger.computed_attribute.attribute.name) |
312 | | - for trigger in triggers |
313 | | - } |
314 | | - for branch, kind, attribute_name in unique_nodes: |
315 | | - if event_name != BranchDeletedEvent.event_name and branch == branch_name: |
316 | | - await service.workflow.submit_workflow( |
317 | | - workflow=TRIGGER_UPDATE_JINJA_COMPUTED_ATTRIBUTES, |
318 | | - context=context, |
319 | | - parameters={ |
320 | | - "branch_name": branch, |
321 | | - "computed_attribute_name": attribute_name, |
322 | | - "computed_attribute_kind": kind, |
323 | | - }, |
324 | | - ) |
325 | | - |
326 | 309 | # Configure all ComputedAttrJinja2Trigger in Prefect |
327 | 310 | async with get_client(sync_client=False) as prefect_client: |
328 | | - await setup_triggers( |
| 311 | + report: TriggerSetupReport = await setup_triggers( |
329 | 312 | client=prefect_client, |
330 | 313 | triggers=triggers, |
331 | 314 | trigger_type=TriggerType.COMPUTED_ATTR_JINJA2, |
332 | 315 | force_update=False, |
333 | 316 | ) # type: ignore[misc] |
334 | 317 |
|
| 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 | + |
335 | 336 | log.info(f"{len(triggers)} Computed Attribute for Jinja2 automation configuration completed") |
336 | 337 |
|
337 | 338 |
|
|
0 commit comments