Skip to content

Commit

Permalink
Show task history link in visualizer when recording. (#2759)
Browse files Browse the repository at this point in the history
* Show task history link in visualizer when recording.

* Fix test.
  • Loading branch information
riga authored and dlstadther committed Aug 20, 2019
1 parent 9e0061d commit 7f67fbc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions luigi/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,10 @@ def get_scheduler_message_response(self, task_id, message_id):
response = task.scheduler_message_responses.pop(message_id, None)
return {"response": response}

@rpc_method()
def has_task_history(self):
return self._config.record_task_history

@rpc_method()
def is_pause_enabled(self):
return {'enabled': self._config.pause_enabled}
Expand Down
10 changes: 9 additions & 1 deletion luigi/static/visualiser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ <h3 class="box-title">{{name}}</h3>
</div>
</script>

<script type="text/template" name="topNavbarItem">
<li>
<a class="js-nav-link" href="{{href}}" {{#dataTab}}data-tab="{{dataTab}}"{{/dataTab}}>
{{label}}
</a>
</li>
</script>

</head>
<body class="skin-green-light fixed">
<div class="modal fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Expand All @@ -388,7 +396,7 @@ <h3 class="box-title">{{name}}</h3>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<ul class="nav navbar-nav" id="topNavbar">
<li><a class="js-nav-link" href="#tab=tasks" data-tab="taskList">Task List</a></li>
<li><a class="js-nav-link" href="#tab=graph" data-tab="dependencyGraph">Dependency Graph</a></li>
<li><a class="js-nav-link" href="#tab=workers" data-tab="workerList">Workers</a></li>
Expand Down
6 changes: 6 additions & 0 deletions luigi/static/visualiser/js/luigi.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ var LuigiAPI = (function() {
});
};

LuigiAPI.prototype.hasTaskHistory = function(callback) {
jsonRPC(this.urlRoot + '/has_task_history', {}, function(response) {
callback(response.response);
});
};

LuigiAPI.prototype.pause = function() {
jsonRPC(this.urlRoot + '/pause');
};
Expand Down
9 changes: 9 additions & 0 deletions luigi/static/visualiser/js/visualiserApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,15 @@ function visualiserApp(luigi) {
$(document).ready(function() {
loadTemplates();

luigi.hasTaskHistory(function(hasTaskHistory) {
if (hasTaskHistory) {
$('#topNavbar').append(renderTemplate('topNavbarItem', {
label: "History",
href: "../../history",
}).children()[0]);
}
});

luigi.isPauseEnabled(function(enabled) {
if (enabled) {
luigi.isPaused(createPauseToggle);
Expand Down
14 changes: 14 additions & 0 deletions test/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from helpers import unittest

import luigi.scheduler
import luigi.configuration
from helpers import with_config


Expand Down Expand Up @@ -229,6 +230,19 @@ def test_per_task_retry_policy(self):
task_9.add_failure()
self.assertTrue(task_9.has_excessive_failures())

@with_config({'scheduler': {'record_task_history': 'true'}})
def test_has_task_history(self):
cfg = luigi.configuration.get_config()
with tempfile.NamedTemporaryFile(suffix='.db', delete=True) as fn:
cfg.set('task_history', 'db_connection', 'sqlite:///' + fn.name)
s = luigi.scheduler.Scheduler()
self.assertTrue(s.has_task_history())

@with_config({'scheduler': {'record_task_history': 'false'}})
def test_has_no_task_history(self):
s = luigi.scheduler.Scheduler()
self.assertFalse(s.has_task_history())

@with_config({'scheduler': {'pause_enabled': 'false'}})
def test_pause_disabled(self):
s = luigi.scheduler.Scheduler()
Expand Down

0 comments on commit 7f67fbc

Please sign in to comment.