Skip to content

Commit

Permalink
UI - clear asks for confirmation, shows a list of task instances
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Dec 10, 2014
1 parent 7c60c4c commit c339ecf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ TODO
* Tree view: remove dummy root node
* Backfill wizard
* Fix datepicker
* Confirm message on clear with list of tasks instances

#### Write unittests
* For each existing operator
Expand All @@ -27,7 +26,6 @@ TODO
* Master to derive BaseJob
* Clear should kill running jobs
* Mysql port should carry through
* Command line, confirm on clear, show list

#### Misc
* Write an hypervisor, looks for dead jobs without a heartbeat and kills
Expand Down
61 changes: 47 additions & 14 deletions airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,56 @@ def action(self):
past = request.args.get('past') == "true"
upstream = request.args.get('upstream') == "true"
downstream = request.args.get('downstream') == "true"
confirmed = request.args.get('confirmed') == "true"

if confirmed:
end_date = execution_date if not future else None
start_date = execution_date if not past else None

count = task.clear(
start_date=start_date,
end_date=end_date,
upstream=upstream,
downstream=downstream)

flash("{0} task instances have been cleared".format(count))
return redirect(origin)
else:
TI = models.TaskInstance
qry = session.query(TI).filter(TI.dag_id == dag_id)

if not future:
qry = qry.filter(TI.execution_date <= execution_date)
if not past:
qry = qry.filter(TI.execution_date >= execution_date)

tasks = [task_id]

if upstream:
tasks += \
[t.task_id for t in task.get_flat_relatives(upstream=True)]
if downstream:
tasks += \
[t.task_id for t in task.get_flat_relatives(upstream=False)]

qry = qry.filter(TI.task_id.in_(tasks))
if not qry.count():
flash("No task instances to clear", 'error')
response = redirect(origin)
else:
details = "\n".join([str(t) for t in qry])

start_date = execution_date
end_date = execution_date

if future:
end_date = None
if past:
start_date = None
response = self.render(
'airflow/confirm.html',
message=(
"Here's the list of task instances you are about "
"to clear:"),
details=details,)

count = task.clear(
start_date=start_date,
end_date=end_date,
upstream=upstream,
downstream=downstream)
session.commit()
session.close()
return response

flash("{0} task instances have been cleared".format(count))
return redirect(origin)

@expose('/tree')
def tree(self):
Expand Down
18 changes: 18 additions & 0 deletions airflow/www/templates/airflow/confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "airflow/master.html" %}

{% block body %}
{{ super() }}
<h2>Wait a minute.</h2>
<div class="panel">
<p>{{ message }}</p>
{% if details %}
<pre><code>{{ details }}</code></pre>
{% endif %}
</div>
<button class="btn btn-primary" onclick="window.location += '&confirmed=true'">
Ok!
</button>
<button class="btn" onclick="window.history.back()">bail.</button>
<br>
<br>
{% endblock %}

0 comments on commit c339ecf

Please sign in to comment.