-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Add task instance management commands to airflowctl CLI #67947
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
cdeb817
326c963
eb51ad6
f265e40
f9d7127
f062780
dcaa410
2a18fa3
d80a10e
18ab353
99f767f
51287e8
ccc0ea4
239572a
93cf5cd
5e5b869
16a59b9
7313c23
a6558b4
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 |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| BulkBodyPoolBody, | ||
| BulkBodyVariableBody, | ||
| BulkResponse, | ||
| ClearTaskInstancesBody, | ||
| Config, | ||
| ConnectionBody, | ||
| ConnectionCollectionResponse, | ||
|
|
@@ -59,6 +60,7 @@ | |
| ImportErrorCollectionResponse, | ||
| ImportErrorResponse, | ||
| JobCollectionResponse, | ||
| PatchTaskInstanceBody, | ||
| PluginCollectionResponse, | ||
| PluginImportErrorCollectionResponse, | ||
| PoolBody, | ||
|
|
@@ -68,6 +70,8 @@ | |
| ProviderCollectionResponse, | ||
| QueuedEventCollectionResponse, | ||
| QueuedEventResponse, | ||
| TaskInstanceCollectionResponse, | ||
| TaskInstanceResponse, | ||
| TriggerDAGRunPostBody, | ||
| VariableBody, | ||
| VariableCollectionResponse, | ||
|
|
@@ -733,10 +737,16 @@ def delete(self, pool: str) -> str | ServerResponseError: | |
|
|
||
| def update(self, pool_body: PoolPatchBody) -> PoolResponse | ServerResponseError: | ||
| """Update a pool.""" | ||
| try: | ||
| self.response = self.client.patch( | ||
| f"pools/{pool_body.pool}", json=pool_body.model_dump(mode="json") | ||
| ) | ||
| # Workaround: the server's PATCH handler validates the partial body | ||
| # against ``BasePool`` (see airflow-core/.../services/public/pools.py) | ||
| # which requires ``include_deferred``. Omitting it fails with | ||
| # "Field required", sending ``null`` fails with "bool_type". Always | ||
| # send ``include_deferred`` (defaulting to False when unset) so PATCH | ||
| # requests are accepted until the server switches to a partial validator. | ||
| body = pool_body.model_dump(mode="json", exclude_none=True) | ||
| body.setdefault("include_deferred", False) | ||
|
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. Could we add a regression test for updating only
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. For example, if the pool currently has |
||
| try: | ||
| self.response = self.client.patch(f"pools/{pool_body.pool}", json=body) | ||
| return PoolResponse.model_validate_json(self.response.content) | ||
| except ServerResponseError as e: | ||
| raise e | ||
|
|
@@ -950,3 +960,45 @@ def list_import_errors(self) -> PluginImportErrorCollectionResponse | ServerResp | |
| return PluginImportErrorCollectionResponse.model_validate_json(self.response.content) | ||
| except ServerResponseError as e: | ||
| raise e | ||
|
|
||
|
|
||
| class TasksOperations(BaseOperations): | ||
| """Tasks operations.""" | ||
|
|
||
| def get(self, dag_id: str, dag_run_id: str, task_id: str) -> TaskInstanceResponse: | ||
| """Get a task instance.""" | ||
| self.response = self.client.get(f"dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}") | ||
| return TaskInstanceResponse.model_validate_json(self.response.content) | ||
|
|
||
| def list(self, dag_id: str, dag_run_id: str) -> TaskInstanceCollectionResponse | ServerResponseError: | ||
| """List task instances.""" | ||
| return super().execute_list( | ||
| path=f"dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances", | ||
| data_model=TaskInstanceCollectionResponse, | ||
| ) | ||
|
|
||
| def clear( | ||
| self, dag_id: str, body: ClearTaskInstancesBody | ||
| ) -> TaskInstanceCollectionResponse | ServerResponseError: | ||
| """Clear task instances.""" | ||
| self.response = self.client.post( | ||
| f"dags/{dag_id}/clearTaskInstances", | ||
| json=body.model_dump(mode="json", exclude_unset=True), | ||
| ) | ||
| return TaskInstanceCollectionResponse.model_validate_json(self.response.content) | ||
|
|
||
| def update( | ||
| self, | ||
| dag_id: str, | ||
| dag_run_id: str, | ||
| task_id: str, | ||
| body: PatchTaskInstanceBody, | ||
| map_index: int | None = None, | ||
| ) -> TaskInstanceCollectionResponse: | ||
| """Update task instance state. When map_index is given, only that mapped instance is affected.""" | ||
| if map_index is not None: | ||
| path = f"dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}/{map_index}" | ||
| else: | ||
| path = f"dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances/{task_id}" | ||
| self.response = self.client.patch(path, json=body.model_dump(mode="json", exclude_unset=True)) | ||
| return TaskInstanceCollectionResponse.model_validate_json(self.response.content) | ||
Uh oh!
There was an error while loading. Please reload this page.