ashb commented on code in PR #60152:
URL: https://github.com/apache/airflow/pull/60152#discussion_r2687511128
##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -1059,46 +1059,62 @@ async def cleanup_finished_triggers(self) -> list[int]:
await asyncio.sleep(0)
return finished_ids
- async def sync_state_to_supervisor(self, finished_ids: list[int]):
+ def validate_state_changes(self, finished_ids: list[int]) ->
messages.TriggerStateChanges:
# Copy out of our dequeues in threadsafe manner to sync state with
parent
- events_to_send = []
+
+ req_encoder = _new_encoder()
+ events_to_send: list[tuple[int, DiscrimatedTriggerEvent]] = []
+ failures_to_send: list[tuple[int, list[str] | None]] = []
+
while self.events:
- data = self.events.popleft()
- events_to_send.append(data)
+ trigger_id, trigger_event = self.events.popleft()
+
+ try:
+ req_encoder.encode(trigger_event)
+ events_to_send.append((trigger_id, trigger_event))
+ except NotImplementedError as e:
+ logger.error(
+ "Trigger %s returned non-serializable result %r.
Cancelling trigger.",
+ trigger_id,
+ trigger_event,
+ )
+ self.failed_triggers.append((trigger_id, e))
Review Comment:
Probably best to catch any error.
Though I don't love the fact that this encodes things twice, throwing the
result away once.
```suggestion
try:
req_encoder.encode(trigger_event)
except Exception as e:
logger.error(
"Trigger %s returned non-serializable result %r.
Cancelling trigger.",
trigger_id,
trigger_event,
)
self.failed_triggers.append((trigger_id, e))
else:
events_to_send.append((trigger_id, trigger_event))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]