Skip to content

Commit

Permalink
Add configuration to enable/disable the pause button (#2399)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwang authored and Tarrasch committed Apr 17, 2018
1 parent 4af1d22 commit 1b2f0fd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ worker_disconnect_delay
scheduler before removing it and marking all of its running tasks as
failed. Defaults to 60.

pause_enabled
If false, disables pause/unpause operations and hides the pause toggle from
the visualiser.


[sendgrid]
----------
Expand Down
12 changes: 10 additions & 2 deletions luigi/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class scheduler(Config):

prune_on_get_work = parameter.BoolParameter(default=False)

pause_enabled = parameter.BoolParameter(default=True)

def _get_retry_policy(self):
return RetryPolicy(self.retry_count, self.disable_hard_timeout, self.disable_window)

Expand Down Expand Up @@ -930,17 +932,23 @@ def disable_worker(self, worker):
def set_worker_processes(self, worker, n):
self._state.get_worker(worker).add_rpc_message('set_worker_processes', n=n)

@rpc_method()
def is_pause_enabled(self):
return {'enabled': self._config.pause_enabled}

@rpc_method()
def is_paused(self):
return {'paused': self._paused}

@rpc_method()
def pause(self):
self._paused = True
if self._config.pause_enabled:
self._paused = True

@rpc_method()
def unpause(self):
self._paused = False
if self._config.pause_enabled:
self._paused = False

@rpc_method()
def update_resources(self, **resources):
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 @@ -158,6 +158,12 @@ var LuigiAPI = (function() {
});
};

LuigiAPI.prototype.isPauseEnabled = function(callback) {
jsonRPC(this.urlRoot + '/is_pause_enabled', {}, function(response) {
callback(response.response.enabled);
});
};

LuigiAPI.prototype.pause = function() {
jsonRPC(this.urlRoot + '/pause');
};
Expand Down
6 changes: 5 additions & 1 deletion luigi/static/visualiser/js/visualiserApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,11 @@ function visualiserApp(luigi) {
$(document).ready(function() {
loadTemplates();

luigi.isPaused(createPauseToggle);
luigi.isPauseEnabled(function(enabled) {
if (enabled) {
luigi.isPaused(createPauseToggle);
}
});

luigi.getWorkerList(function(workers) {
$("#workerList").append(renderWorkers(workers));
Expand Down
8 changes: 8 additions & 0 deletions test/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ def test_per_task_retry_policy(self):
task_9.add_failure()
self.assertTrue(task_9.has_excessive_failures())

@with_config({'scheduler': {'pause_enabled': 'false'}})
def test_pause_disabled(self):
s = luigi.scheduler.Scheduler()
self.assertFalse(s.is_pause_enabled()['enabled'])
self.assertFalse(s.is_paused()['paused'])
s.pause()
self.assertFalse(s.is_paused()['paused'])


class SchedulerWorkerTest(unittest.TestCase):
def get_pending_ids(self, worker, state):
Expand Down

0 comments on commit 1b2f0fd

Please sign in to comment.