-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
AIP 72: Handling deferrable tasks in execution API as well as TASK SDK #44241
base: main
Are you sure you want to change the base?
Changes from all commits
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,15 +17,17 @@ | |
|
||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
from unittest import mock | ||
|
||
import pytest | ||
from sqlalchemy import select | ||
from sqlalchemy.exc import SQLAlchemyError | ||
|
||
from airflow.models import Trigger | ||
from airflow.models.taskinstance import TaskInstance | ||
from airflow.utils import timezone | ||
from airflow.utils.state import State | ||
from airflow.utils.state import State, TaskInstanceState | ||
|
||
from tests_common.test_utils.db import clear_db_runs | ||
|
||
|
@@ -193,6 +195,49 @@ def test_ti_update_state_database_error(self, client, session, create_task_insta | |
assert response.status_code == 500 | ||
assert response.json()["detail"] == "Database error occurred" | ||
|
||
def test_ti_update_state_to_deferred(self, client, session, create_task_instance): | ||
""" | ||
Test that tests if the transition to deferred state is handled correctly. | ||
""" | ||
|
||
ti = create_task_instance( | ||
task_id="test_ti_update_state_to_deferred", | ||
state=State.RUNNING, | ||
session=session, | ||
) | ||
session.commit() | ||
|
||
payload = { | ||
"state": "deferred", | ||
"classpath": "my-class-path", | ||
"kwargs": {}, | ||
"created_date": "2024-10-31T12:00:00Z", | ||
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. Hmm, why is this being sent in the payload? Should it be the time the server received the request instead? 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 is handled this way:
In case we do not pass it, it will take the UTC now. Should we allow the option to override it or remove it entirely? |
||
"next_method": "execute_callback", | ||
"timeout": None, | ||
} | ||
|
||
response = client.patch(f"/execution/task-instances/{ti.id}/state", json=payload) | ||
|
||
assert response.status_code == 204 | ||
assert response.text == "" | ||
|
||
session.expire_all() | ||
|
||
t = session.query(Trigger).all() | ||
assert len(t) == 1 | ||
assert t[0].created_date == datetime(2024, 10, 31, 12, 0, tzinfo=timezone.utc) | ||
assert t[0].classpath == "my-class-path" | ||
assert t[0].kwargs == {} | ||
|
||
tis = session.query(TaskInstance).all() | ||
assert len(tis) == 1 | ||
|
||
assert tis[0].state == TaskInstanceState.DEFERRED | ||
assert tis[0].trigger_id == t[0].id | ||
assert tis[0].next_method == "execute_callback" | ||
assert tis[0].next_kwargs == {} | ||
assert tis[0].trigger_timeout is None | ||
|
||
|
||
class TestTIHealthEndpoint: | ||
def setup_method(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeout shouldn't be days!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to handle it better based on what I can send from the client, this isn't right yet