Permalink
Browse files

refactoring: eliminate DRY violation by creating status() routine

  • Loading branch information...
lirazsiri committed Dec 19, 2012
1 parent de7d32b commit c9ac3b93ed74309c2d8dfb7b8ec25913d3e00148
Showing with 9 additions and 6 deletions.
  1. +9 −6 cloudtask/task.py
View
@@ -351,8 +351,12 @@ def main(cls):
@classmethod
def work(cls, jobs, split, session, taskconf):
- timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
- print >> session.mlog, "%s :: session %d (pid %d)\n" % (timestamp, session.id, os.getpid())
+ def status(msg):
+ timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
+ session.mlog.write("%s :: session %d %s\n" % (timestamp, session.id, msg))
+
+ status("(pid %d)" % os.getpid())
+ print >> session.mlog
class CaughtSignal(CloudWorker.Terminated):
pass
@@ -407,10 +411,9 @@ def terminate(sig, f):
total = len(session.jobs.finished) + len(session.jobs.pending)
- timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
- print >> session.mlog, "\n%s :: session %d (%d seconds): %d/%d !OK - %d pending, %d timeouts, %d errors, %d OK" % \
- (timestamp, session.id, session.elapsed,
- total - succeeded, total, len(session.jobs.pending), timeouts, errors, succeeded)
+ print >> session.mlog
+ status("(%d seconds): %d/%d !OK - %d pending, %d timeouts, %d errors, %d OK" % \
+ (session.elapsed, total - succeeded, total, len(session.jobs.pending), timeouts, errors, succeeded))
return (total - succeeded == 0)

0 comments on commit c9ac3b9

Please sign in to comment.