Skip to content
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

Show "Task Reschedule" table in Airflow Webserver #9521

Merged
merged 2 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airflow/www/extensions/init_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def init_appbuilder_views(app):
appbuilder.add_view(views.LogModelView, "Logs", category="Browse")
appbuilder.add_view(views.SlaMissModelView, "SLA Misses", category="Browse")
appbuilder.add_view(views.TaskInstanceModelView, "Task Instances", category="Browse")
appbuilder.add_view(views.TaskRescheduleModelView, "Task Reschedules", category="Browse")
appbuilder.add_view(views.ConfigurationView, "Configurations", category="Admin", category_icon="fa-user")
appbuilder.add_view(views.ConnectionModelView, "Connections", category="Admin")
appbuilder.add_view(views.PoolModelView, "Pools", category="Admin")
Expand Down
35 changes: 35 additions & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2617,6 +2617,41 @@ class LogModelView(AirflowModelView):
}


class TaskRescheduleModelView(AirflowModelView):
"""View to show records from Task Reschedule table"""
route_base = '/taskreschedule'

datamodel = AirflowModelView.CustomSQLAInterface(models.TaskReschedule)

base_permissions = ['can_list']

list_columns = ['id', 'dag_id', 'task_id', 'execution_date', 'try_number',
'start_date', 'end_date', 'duration', 'reschedule_date']

search_columns = ['dag_id', 'task_id', 'execution_date', 'start_date', 'end_date',
'reschedule_date']

base_order = ('id', 'desc')

base_filters = [['dag_id', DagFilter, lambda: []]]

def duration_f(attr):
end_date = attr.get('end_date')
duration = attr.get('duration')
if end_date and duration:
return timedelta(seconds=duration)

formatters_columns = {
'dag_id': wwwutils.dag_link,
'task_id': wwwutils.task_instance_link,
'start_date': wwwutils.datetime_f('start_date'),
'end_date': wwwutils.datetime_f('end_date'),
'execution_date': wwwutils.datetime_f('execution_date'),
'reschedule_date': wwwutils.datetime_f('reschedule_date'),
'duration': duration_f,
}


class TaskInstanceModelView(AirflowModelView):
"""View to show records from TaskInstance table"""
route_base = '/taskinstance'
Expand Down
14 changes: 13 additions & 1 deletion tests/www/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def prepare_dagruns(self):
state=State.RUNNING)

def test_index(self):
with assert_queries_count(39):
with assert_queries_count(40):
resp = self.client.get('/', follow_redirects=True)
self.check_content_in_response('DAGs', resp)

Expand Down Expand Up @@ -2227,6 +2227,18 @@ def test_start_date_filter(self):
self.check_content_in_response('List Task Instance', resp)


class TestTaskRescheduleView(TestBase):
TI_ENDPOINT = '/taskreschedule/list/?_flt_0_execution_date={}'

def test_start_date_filter(self):
resp = self.client.get(self.TI_ENDPOINT.format(
self.percent_encode('2018-10-09 22:44:31')))
# We aren't checking the logic of the date filter itself (that is built
# in to FAB) but simply that our UTC conversion was run - i.e. it
# doesn't blow up!
self.check_content_in_response('List Task Reschedule', resp)


class TestRenderedView(TestBase):

def setUp(self):
Expand Down