Mercurial > repos > yufei-luo > s_mart
comparison commons/core/launcher/JobScriptTemplate.py @ 6:769e306b7933
Change the repository level.
| author | yufei-luo |
|---|---|
| date | Fri, 18 Jan 2013 04:54:14 -0500 |
| parents | |
| children | 94ab73e8a190 |
comparison
equal
deleted
inserted
replaced
| 5:ea3082881bf8 | 6:769e306b7933 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 import os | |
| 4 import sys | |
| 5 import time | |
| 6 import shutil | |
| 7 from commons.core.checker.RepetException import RepetException | |
| 8 from commons.core.sql.TableJobAdaptator import TableJobAdaptator | |
| 9 from commons.core.sql.DbFactory import DbFactory | |
| 10 from commons.core.sql.Job import Job | |
| 11 | |
| 12 try: | |
| 13 newDir = None | |
| 14 print os.uname() | |
| 15 beginTime = time.time() | |
| 16 print 'beginTime=%f' % beginTime | |
| 17 print "work in dir '@@tmpDir@@'" | |
| 18 sys.stdout.flush() | |
| 19 if not os.path.exists( "@@tmpDir@@" ): | |
| 20 raise IOError("ERROR: temporary directory '@@tmpDir@@' doesn't exist") | |
| 21 | |
| 22 minFreeGigaInTmpDir = 1 | |
| 23 freeSpace = os.statvfs("@@tmpDir@@") | |
| 24 if ((freeSpace.f_bavail * freeSpace.f_frsize) / 1073741824.0 < minFreeGigaInTmpDir): | |
| 25 raise RepetException("ERROR: less than %iG of input file in '@@tmpDir@@'" % minFreeGigaInTmpDir) | |
| 26 | |
| 27 os.chdir("@@tmpDir@@") | |
| 28 newDir = "@@groupId@@_@@jobName@@_@@time@@" | |
| 29 if os.path.exists(newDir): | |
| 30 shutil.rmtree(newDir) | |
| 31 os.mkdir(newDir) | |
| 32 os.chdir(newDir) | |
| 33 | |
| 34 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME")) | |
| 35 iDb = DbFactory.createInstance() | |
| 36 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@") | |
| 37 print "current status: %s" % iTJA.getJobStatus(iJob) | |
| 38 iTJA.changeJobStatus(iJob, "running") | |
| 39 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
| 40 sys.stdout.flush() | |
| 41 iDb.close() | |
| 42 | |
| 43 @@cmdStart@@ | |
| 44 if log != 0: | |
| 45 raise RepetException("ERROR: job returned %i" % log) | |
| 46 else: | |
| 47 print "job finished successfully" | |
| 48 sys.stdout.flush() | |
| 49 @@cmdFinish@@ | |
| 50 | |
| 51 os.chdir("..") | |
| 52 shutil.rmtree(newDir) | |
| 53 | |
| 54 iDb = DbFactory.createInstance() | |
| 55 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@") | |
| 56 print "current status: %s" % iTJA.getJobStatus(iJob) | |
| 57 iTJA.changeJobStatus(iJob, "finished") | |
| 58 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
| 59 sys.stdout.flush() | |
| 60 iDb.close() | |
| 61 | |
| 62 endTime = time.time() | |
| 63 print 'endTime=%f' % endTime | |
| 64 print 'executionTime=%f' % (endTime - beginTime) | |
| 65 print os.uname() | |
| 66 sys.stdout.flush() | |
| 67 | |
| 68 except IOError, e : | |
| 69 print e | |
| 70 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME")) | |
| 71 iDb = DbFactory.createInstance() | |
| 72 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@") | |
| 73 print "current status: %s" % iTJA.getJobStatus(iJob) | |
| 74 iTJA.changeJobStatus(iJob, "error") | |
| 75 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
| 76 sys.stdout.flush() | |
| 77 iDb.close() | |
| 78 sys.exit(1) | |
| 79 | |
| 80 except Exception, e : | |
| 81 print "tmpDir is : @@tmpDir@@" | |
| 82 print "cDir is : @@cDir@@" | |
| 83 print e | |
| 84 if newDir != None and os.path.exists("../%s" % newDir) and not os.path.exists("@@cDir@@/%s" % newDir): | |
| 85 os.chdir("..") | |
| 86 shutil.move(newDir, "@@cDir@@/%s" % newDir) | |
| 87 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME")) | |
| 88 iDb = DbFactory.createInstance() | |
| 89 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@") | |
| 90 print "current status: %s" % iTJA.getJobStatus(iJob) | |
| 91 iTJA.changeJobStatus(iJob, "error") | |
| 92 print "updated status: %s" % iTJA.getJobStatus(iJob) | |
| 93 sys.stdout.flush() | |
| 94 iDb.close() | |
| 95 sys.exit(1) |
