-#!/usr/bin/python
+#!/usr/bin/env python
+""" A simple tool to run jobs from a database in parallel."""
+
+__author__ = "Stefan Huber"
+__copyright__ = "Copyright 2013"
+
+__version__ = "1.0"
+__license__ = "LGPL3"
+
import sys, getopt, os
import sqlite3
c.close()
- print(nototal, nodone, wldone, wltotal)
perdone = 100.0*float(nodone)/float(nototal)
perwl = 100.0*float(wldone)/float(wltotal)
return exitcode, out, err
def processJob(conn, jobid):
- print("Process job %d" % (jobid))
c = conn.cursor()
c.execute("SELECT cmd FROM jobs WHERE id=?", (jobid,))
cmd, = c.fetchone()
+ print("Process job %d: %s" % (jobid, cmd))
+
ec, out, err = runCmd(cmd)
c.execute("UPDATE jobs SET exitcode=?, done=1 WHERE id=?;", (ec, jobid))
OPTIONS:
-d database the database to process
+ -n num in -w mode, only perform num-many jobs
-p cols-def create properties table with SQL column spec
-v print output of the job's command
propdef = None
work = False
status = False
+ numjobs = None
try:
- opts, args = getopt.getopt(sys.argv[1:], "hd:c:p:wsv")
+ opts, args = getopt.getopt(sys.argv[1:], "hd:c:p:wsvn:")
for opt, arg in opts:
if opt == "-h":
status = True
elif opt == "-v":
verbose = True
+ elif opt == "-n":
+ numjobs = int(arg)
else:
print("Unknown option '", opt, "'.")
insertJobs(conn, cmds)
if work:
- while True:
+ n = 0
+ while not numjobs or n < numjobs:
+
jobid = getNextJobId(conn)
if jobid == None:
print("All jobs have been started.")
break
processJob(conn, jobid)
+ n += 1
conn.close()