Skip to content
Browse files

refactoring: separated work logic from main cli interface logic

  • Loading branch information...
1 parent 380237d commit de7d32b4eee0c785a0cfa68a7a96ab65916dd222 @lirazsiri lirazsiri committed Dec 19, 2012
Showing with 15 additions and 9 deletions.
  1. +15 −9 cloudtask/task.py
View
24 cloudtask/task.py
@@ -66,7 +66,7 @@
"""
import os
-from os.path import *
+from os.path import isdir
import sys
import shlex
import getopt
@@ -169,11 +169,11 @@ def main(cls):
if cls.SESSIONS:
opt_sessions = cls.SESSIONS
if not opt_sessions.startswith('/'):
- opt_sessions = join(dirname(sys.argv[0]), opt_sessions)
+ opt_sessions = os.path.join(dirname(sys.argv[0]), opt_sessions)
else:
opt_sessions = os.environ.get('CLOUDTASK_SESSIONS',
- join(os.environ['HOME'], '.cloudtask'))
+ os.path.join(os.environ['HOME'], '.cloudtask'))
for opt, val in opts:
if opt in ('-h', '--help'):
@@ -340,6 +340,17 @@ def main(cls):
session.taskconf = taskconf
+ ok = cls.work(jobs, split, session, taskconf)
+
+ if reporter:
+ reporter.report(session)
+
+ if not ok:
+ sys.exit(1)
+
+ @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())
@@ -400,13 +411,8 @@ def terminate(sig, f):
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)
-
-
- if reporter:
- reporter.report(session)
- if succeeded != total:
- sys.exit(1)
+ return (total - succeeded == 0)
# set default class values to TaskConf defaults
for attr in TaskConf.__all__:

0 comments on commit de7d32b

Please sign in to comment.
Something went wrong with that request. Please try again.