Skip to content

Commit 1b2f0fd

Browse files
kevinwangTarrasch
authored andcommitted
Add configuration to enable/disable the pause button (spotify#2399)
1 parent 4af1d22 commit 1b2f0fd

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

doc/configuration.rst

+4
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ worker_disconnect_delay
722722
scheduler before removing it and marking all of its running tasks as
723723
failed. Defaults to 60.
724724

725+
pause_enabled
726+
If false, disables pause/unpause operations and hides the pause toggle from
727+
the visualiser.
728+
725729

726730
[sendgrid]
727731
----------

luigi/scheduler.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ class scheduler(Config):
147147

148148
prune_on_get_work = parameter.BoolParameter(default=False)
149149

150+
pause_enabled = parameter.BoolParameter(default=True)
151+
150152
def _get_retry_policy(self):
151153
return RetryPolicy(self.retry_count, self.disable_hard_timeout, self.disable_window)
152154

@@ -930,17 +932,23 @@ def disable_worker(self, worker):
930932
def set_worker_processes(self, worker, n):
931933
self._state.get_worker(worker).add_rpc_message('set_worker_processes', n=n)
932934

935+
@rpc_method()
936+
def is_pause_enabled(self):
937+
return {'enabled': self._config.pause_enabled}
938+
933939
@rpc_method()
934940
def is_paused(self):
935941
return {'paused': self._paused}
936942

937943
@rpc_method()
938944
def pause(self):
939-
self._paused = True
945+
if self._config.pause_enabled:
946+
self._paused = True
940947

941948
@rpc_method()
942949
def unpause(self):
943-
self._paused = False
950+
if self._config.pause_enabled:
951+
self._paused = False
944952

945953
@rpc_method()
946954
def update_resources(self, **resources):

luigi/static/visualiser/js/luigi.js

+6
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ var LuigiAPI = (function() {
158158
});
159159
};
160160

161+
LuigiAPI.prototype.isPauseEnabled = function(callback) {
162+
jsonRPC(this.urlRoot + '/is_pause_enabled', {}, function(response) {
163+
callback(response.response.enabled);
164+
});
165+
};
166+
161167
LuigiAPI.prototype.pause = function() {
162168
jsonRPC(this.urlRoot + '/pause');
163169
};

luigi/static/visualiser/js/visualiserApp.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,11 @@ function visualiserApp(luigi) {
10111011
$(document).ready(function() {
10121012
loadTemplates();
10131013

1014-
luigi.isPaused(createPauseToggle);
1014+
luigi.isPauseEnabled(function(enabled) {
1015+
if (enabled) {
1016+
luigi.isPaused(createPauseToggle);
1017+
}
1018+
});
10151019

10161020
luigi.getWorkerList(function(workers) {
10171021
$("#workerList").append(renderWorkers(workers));

test/scheduler_test.py

+8
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ def test_per_task_retry_policy(self):
229229
task_9.add_failure()
230230
self.assertTrue(task_9.has_excessive_failures())
231231

232+
@with_config({'scheduler': {'pause_enabled': 'false'}})
233+
def test_pause_disabled(self):
234+
s = luigi.scheduler.Scheduler()
235+
self.assertFalse(s.is_pause_enabled()['enabled'])
236+
self.assertFalse(s.is_paused()['paused'])
237+
s.pause()
238+
self.assertFalse(s.is_paused()['paused'])
239+
232240

233241
class SchedulerWorkerTest(unittest.TestCase):
234242
def get_pending_ids(self, worker, state):

0 commit comments

Comments
 (0)