-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Replace _handle_request elif chains with a handler registry #65827 #68106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5531d97
f8d1de1
3f22f84
89c3ed1
6698321
4de5af1
302ef8c
115000e
3d7acdd
f9df3ea
623f64e
1a9ca05
196439d
e392c90
3a047ab
d3bac47
10e8db6
935527d
d4ca9bd
650b8bf
732e367
9c8672a
137bc02
83ecb58
6fd216b
4c5751a
51d7ef5
b303d9e
83b5e03
345af5c
da6d474
cc349e0
068e89a
0f68dda
cdcc7cb
9632656
46d1262
96870a1
f562754
30db227
ce63a0d
237462f
bf958d3
5eeb88f
df344c2
51a28fd
8fe733d
cfceffd
9e240c6
865e0f2
64d7153
5502655
fbed797
b446145
253b8a8
27d21e2
7abcf31
1f99b93
1ab71cd
68ad65d
3be2611
3173a1a
1c106a3
e1066c5
c62a4b4
3d23ebf
b163822
07f83f0
ec2ce98
2aa18b6
e32ff46
3268e88
1cfe827
0d58359
cf9626f
d2906da
518e8a8
6057a00
93d1c61
adb7b3f
33e9e96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import functools | ||
| import logging | ||
| import math | ||
| import os | ||
|
|
@@ -101,30 +100,6 @@ | |
| _RequestFrame, | ||
| ) | ||
| from airflow.sdk.execution_time.context import AssetStateStoreAccessors | ||
| from airflow.sdk.execution_time.request_handlers import ( | ||
| handle_clear_asset_state_store_by_name, | ||
| handle_clear_asset_state_store_by_uri, | ||
| handle_delete_asset_state_store_by_name, | ||
| handle_delete_asset_state_store_by_uri, | ||
| handle_delete_variable, | ||
| handle_delete_xcom, | ||
| handle_get_asset_state_store_by_name, | ||
| handle_get_asset_state_store_by_uri, | ||
| handle_get_connection, | ||
| handle_get_dag_run_state, | ||
| handle_get_dr_count, | ||
| handle_get_previous_ti, | ||
| handle_get_task_states, | ||
| handle_get_ti_count, | ||
| handle_get_variable, | ||
| handle_get_variable_keys, | ||
| handle_get_xcom, | ||
| handle_mask_secret, | ||
| handle_put_variable, | ||
| handle_set_asset_state_store_by_name, | ||
| handle_set_asset_state_store_by_uri, | ||
| handle_set_xcom, | ||
| ) | ||
| from airflow.sdk.execution_time.supervisor import WatchedSubprocess, make_buffered_socket_reader | ||
| from airflow.sdk.execution_time.task_runner import RuntimeTaskInstance | ||
| from airflow.serialization.serialized_objects import DagSerialization | ||
|
|
@@ -484,6 +459,7 @@ class TriggerRunnerSupervisor(WatchedSubprocess): | |
| rather than silently zombieing the supervisor. | ||
| """ | ||
|
|
||
| _msg_union: ClassVar[Any] = ToTriggerSupervisor | ||
| job: Job | None = None | ||
| capacity: int | ||
| queues: set[str] | None = None | ||
|
|
@@ -547,6 +523,7 @@ def start( # type: ignore[override] | |
| proc = super().start( | ||
| id=proc_id, | ||
| job=job, | ||
| client=cls.make_client(), | ||
| target=cls.run_in_process, | ||
| logger=logger, | ||
| use_exec=supervisor._should_use_exec(), | ||
|
|
@@ -558,11 +535,8 @@ def start( # type: ignore[override] | |
| proc.send_msg(msg, request_id=0) | ||
| return proc | ||
|
|
||
| @functools.cached_property | ||
| def client(self) -> Client: | ||
| return self.make_client() | ||
|
|
||
| def make_client(self) -> Client: | ||
| @classmethod | ||
| def make_client(cls) -> Client: | ||
| """ | ||
| Build the API client used to talk to the API server. | ||
|
|
||
|
|
@@ -580,9 +554,6 @@ def make_client(self) -> Client: | |
| return client | ||
|
|
||
| def _handle_request(self, msg: ToTriggerSupervisor, log: FilteringBoundLogger, req_id: int) -> None: | ||
|
|
||
| resp: BaseModel | None = None | ||
| dump_opts: dict[str, bool] = {} | ||
| self._last_runner_comms = time.monotonic() | ||
|
|
||
| if isinstance(msg, messages.TriggerStateChanges): | ||
|
|
@@ -608,85 +579,37 @@ def _handle_request(self, msg: ToTriggerSupervisor, log: FilteringBoundLogger, r | |
| while self.persisted_event_seqs: | ||
| events_persisted.append(self.persisted_event_seqs.popleft()) | ||
|
|
||
| response = messages.TriggerStateSync( | ||
| sync = messages.TriggerStateSync( | ||
| to_create=[], | ||
| to_cancel=self.cancelling_triggers, | ||
| to_cancel=self.cancelling_triggers.copy(), | ||
| events_persisted=events_persisted or None, | ||
| ) | ||
|
|
||
| # Pull out of these dequeues in a thread-safe manner | ||
| while self.creating_triggers: | ||
| workload = self.creating_triggers.popleft() | ||
| response.to_create.append(workload) | ||
| self.running_triggers.update(m.id for m in response.to_create) | ||
| resp = response | ||
|
|
||
| elif isinstance(msg, GetConnection): | ||
| resp, dump_opts = handle_get_connection(self.client, msg) | ||
| elif isinstance(msg, DeleteVariable): | ||
| resp, dump_opts = handle_delete_variable(self.client, msg) | ||
| elif isinstance(msg, GetVariable): | ||
| resp, dump_opts = handle_get_variable(self.client, msg) | ||
| elif isinstance(msg, GetVariableKeys): | ||
| resp, dump_opts = handle_get_variable_keys(self.client, msg) | ||
| elif isinstance(msg, PutVariable): | ||
| resp, dump_opts = handle_put_variable(self.client, msg) | ||
| elif isinstance(msg, DeleteXCom): | ||
| resp, dump_opts = handle_delete_xcom(self.client, msg) | ||
| elif isinstance(msg, GetXCom): | ||
| resp, dump_opts = handle_get_xcom(self.client, msg) | ||
| elif isinstance(msg, SetXCom): | ||
| resp, dump_opts = handle_set_xcom(self.client, msg) | ||
| elif isinstance(msg, GetDRCount): | ||
| resp, dump_opts = handle_get_dr_count(self.client, msg) | ||
| elif isinstance(msg, GetDagRunState): | ||
| resp, dump_opts = handle_get_dag_run_state(self.client, msg) | ||
|
|
||
| elif isinstance(msg, GetTICount): | ||
| resp, dump_opts = handle_get_ti_count(self.client, msg) | ||
|
|
||
| elif isinstance(msg, GetTaskStates): | ||
| resp, dump_opts = handle_get_task_states(self.client, msg) | ||
| elif isinstance(msg, GetPreviousTI): | ||
| resp, dump_opts = handle_get_previous_ti(self.client, msg) | ||
| elif isinstance(msg, UpdateHITLDetail): | ||
| sync.to_create.append(workload) | ||
| self.running_triggers.update(m.id for m in sync.to_create) | ||
| self.send_msg(sync, request_id=req_id, error=None) | ||
| return | ||
|
|
||
| if isinstance(msg, UpdateHITLDetail): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like ToSupervisor has |
||
| api_resp = self.client.hitl.update_response( | ||
| ti_id=msg.ti_id, | ||
| chosen_options=msg.chosen_options, | ||
| params_input=msg.params_input, | ||
| ) | ||
| resp = HITLDetailResponseResult.from_api_response(response=api_resp) | ||
| elif isinstance(msg, GetHITLDetailResponse): | ||
| self.send_msg(resp, request_id=req_id, error=None) | ||
| return | ||
|
|
||
| if isinstance(msg, GetHITLDetailResponse): | ||
| api_resp = self.client.hitl.get_detail_response(ti_id=msg.ti_id) | ||
| resp = HITLDetailResponseResult.from_api_response(response=api_resp) | ||
| elif isinstance(msg, MaskSecret): | ||
| handle_mask_secret(msg) | ||
| elif isinstance(msg, ClearAssetStateStoreByName): | ||
| handle_clear_asset_state_store_by_name(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| elif isinstance(msg, ClearAssetStateStoreByUri): | ||
| handle_clear_asset_state_store_by_uri(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| elif isinstance(msg, DeleteAssetStateStoreByName): | ||
| handle_delete_asset_state_store_by_name(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| elif isinstance(msg, DeleteAssetStateStoreByUri): | ||
| handle_delete_asset_state_store_by_uri(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| elif isinstance(msg, GetAssetStateStoreByName): | ||
| resp, dump_opts = handle_get_asset_state_store_by_name(self.client, msg) | ||
| elif isinstance(msg, GetAssetStateStoreByUri): | ||
| resp, dump_opts = handle_get_asset_state_store_by_uri(self.client, msg) | ||
| elif isinstance(msg, SetAssetStateStoreByName): | ||
| handle_set_asset_state_store_by_name(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| elif isinstance(msg, SetAssetStateStoreByUri): | ||
| handle_set_asset_state_store_by_uri(self.client, msg) | ||
| resp = OKResponse(ok=True) | ||
| else: | ||
| raise ValueError(f"Unknown message type {type(msg)}") | ||
| self.send_msg(resp, request_id=req_id, error=None) | ||
| return | ||
|
|
||
| self.send_msg(resp, request_id=req_id, error=None, **dump_opts) | ||
| super()._handle_request(msg, log, req_id) | ||
|
|
||
| def run(self) -> None: | ||
| """Run synchronously and handle all database reads/writes.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.