Skip to content

Commit 598dffe

Browse files
committed
Addressed @mgermain comments
1 parent 67d6bf3 commit 598dffe

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

scripts/smart_worker.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,17 @@ def main():
4545
stdout_filename = os.path.join(args.logs_dir, uid + ".out")
4646
stderr_filename = os.path.join(args.logs_dir, uid + ".err")
4747

48-
stdout_already_exists = os.path.isfile(stdout_filename)
49-
stderr_already_exists = os.path.isfile(stderr_filename)
50-
5148
with open(stdout_filename, 'a') as stdout_file:
5249
with open(stderr_filename, 'a') as stderr_file:
53-
if stdout_already_exists:
54-
stdout_file.write('\n')
50+
log_datetime = t.strftime("## SMART_DISPATCH - Started on: %Y-%m-%d %H:%M:%S ##\n")
51+
if stdout_file.tell() > 0: # Not the first line in the log file.
52+
log_datetime = t.strftime("\n## SMART_DISPATCH - Resumed on: %Y-%m-%d %H:%M:%S ##\n")
5553

56-
if stderr_already_exists:
57-
stderr_file.write('\n')
54+
log_command = "## SMART_DISPATCH - Command: " + command + '\n'
5855

59-
stdout_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
60-
stdout_file.write("# " + command + '\n')
56+
stdout_file.write(log_datetime + log_command)
6157
stdout_file.flush()
62-
stderr_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
63-
stderr_file.write("# " + command + '\n')
58+
stderr_file.write(log_datetime + log_command)
6459
stderr_file.flush()
6560

6661
error_code = subprocess.call(command, stdout=stdout_file, stderr=stderr_file, shell=True)

tests/test_smart_worker.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@ def test_main(self):
4545
executed_command = self.commands[self.commands_uid.index(uid)]
4646

4747
# Since the command was run twice.
48-
for _ in range(2):
48+
for i in range(2):
4949
# First line is the datetime of the executed command in comment.
5050
line = logfile.readline().strip()
51-
assert_true(time.strftime("## %Y-%m-%d %H:%M:") in line) # Don't check seconds.
51+
52+
if i == 0:
53+
assert_true("Started" in line)
54+
else:
55+
assert_true("Resumed" in line)
56+
57+
assert_true(line.startswith("## SMART_DISPATCH"))
58+
assert_true(time.strftime("%Y-%m-%d %H:%M:") in line) # Don't check seconds.
5259

5360
# Second line is the executed command in comment.
5461
line = logfile.readline().strip()
55-
assert_equal(line, "# " + executed_command)
62+
assert_true(executed_command in line)
5663

5764
# Next should be the command's output
5865
line = logfile.readline().strip()
@@ -73,14 +80,21 @@ def test_main(self):
7380
executed_command = self.commands[self.commands_uid.index(uid)]
7481

7582
# Since the command was run twice.
76-
for _ in range(2):
83+
for i in range(2):
7784
# First line is the datetime of the executed command in comment.
7885
line = logfile.readline().strip()
79-
assert_true(time.strftime("## %Y-%m-%d %H:%M:") in line) # Don't check seconds.
86+
87+
if i == 0:
88+
assert_true("Started" in line)
89+
else:
90+
assert_true("Resumed" in line)
91+
92+
assert_true(line.startswith("## SMART_DISPATCH"))
93+
assert_true(time.strftime("%Y-%m-%d %H:%M:") in line) # Don't check seconds.
8094

8195
# Second line is the executed command in comment.
8296
line = logfile.readline().strip()
83-
assert_equal(line, "# " + executed_command)
97+
assert_true(executed_command in line)
8498

8599
# Empty line
86100
assert_equal(logfile.readline().strip(), "")

0 commit comments

Comments
 (0)