From 7d5ad1f18b6ef2f767cf6a6bb60978e02a4b75f1 Mon Sep 17 00:00:00 2001 From: Mathieu Germain Date: Thu, 4 Dec 2014 13:52:14 -0500 Subject: [PATCH] Added get_nb_commands_to_run() to command_manager --- scripts/smart_dispatch.py | 1 + smartdispatch/command_manager.py | 4 ++++ smartdispatch/tests/test_command_manager.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/scripts/smart_dispatch.py b/scripts/smart_dispatch.py index 78041da..3a3544c 100755 --- a/scripts/smart_dispatch.py +++ b/scripts/smart_dispatch.py @@ -59,6 +59,7 @@ def main(): command_manager.set_commands_to_run(commands) else: command_manager.reset_running_commands() + nb_commands = command_manager.get_nb_commands_to_run() worker_command = 'smart_worker.py "{0}" "{1}"'.format(command_manager._commands_filename, path_job_logs) # Replace commands with `args.pool` workers diff --git a/smartdispatch/command_manager.py b/smartdispatch/command_manager.py index 79bb964..3f2c388 100644 --- a/smartdispatch/command_manager.py +++ b/smartdispatch/command_manager.py @@ -36,6 +36,10 @@ def get_command_to_run(self): self._move_line_between_files(commands_file, running_commands_file, command) return command[:-1] + def get_nb_commands_to_run(self): + with utils.open_with_lock(self._commands_filename, 'r') as commands_file: + return len(commands_file.readline()) + def set_running_command_as_finished(self, command): with utils.open_with_lock(self._running_commands_filename, 'r+') as running_commands_file: with utils.open_with_lock(self._finished_commands_filename, 'a') as finished_commands_file: diff --git a/smartdispatch/tests/test_command_manager.py b/smartdispatch/tests/test_command_manager.py index 10f9af1..966dbfe 100644 --- a/smartdispatch/tests/test_command_manager.py +++ b/smartdispatch/tests/test_command_manager.py @@ -55,6 +55,9 @@ def test_get_command_to_run(self): assert_true(not os.path.isfile(self.command_manager._finished_commands_filename)) + def test_get_nb_commands_to_run(self): + assert_equal(self.command_manager.get_nb_commands_to_run(), 3) + def test_set_running_command_as_finished(self): # SetUp command = self.command_manager.get_command_to_run()