Skip to content

Commit

Permalink
Added get_nb_commands_to_run() to command_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermain committed Dec 4, 2014
1 parent 221d49e commit 7d5ad1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/smart_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions smartdispatch/command_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions smartdispatch/tests/test_command_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7d5ad1f

Please sign in to comment.