|
def | parseConnectionInfo (self, connstring='') |
|
def | __init__ (self, connstring='', createDatabase=False) |
|
def | __enter__ (self) |
|
def | __exit__ (self, exc_type, exc_value, traceback) |
|
def | execute (self, statementParts, doCommit=False, limit=None) |
|
def | deleteTask (self, dsName, taskName) |
|
def | addTask (self, dsName, taskName, template, release, njobs, taskpostprocsteps='', status=StatusCodes['SUBMITTED'], onDisk=OnDiskCodes['ALLONDISK'], createdTime=None, createdUser=None, createdHost=None, comment='') |
|
def | getStatus (self, dsName, taskName) |
|
def | setStatus (self, dsName, taskName, status, oldStatus=None) |
|
def | setDiskStatus (self, dsName, taskName, onDisk) |
|
def | updateStatus (self, dsName, taskName, status, nResultFiles, nJobs, nJobsSubmitted, nJobsRunning, nJobsPostProc, nJobsFailed, nJobsCompleted) |
|
def | setValue (self, dsName, taskName, fieldName, value) |
|
def | getValue (self, what, qual=()) |
|
def | getCount (self, what, qual=()) |
|
def | getNTasks (self, qual=()) |
|
def | getTaskValue (self, dsName, taskName, what) |
|
def | taskIter (self, what=' *', qual=('order by UPDATED',)) |
|
def | taskIterDict (self, what=' *', qual=('order by UPDATED',), limit=999999999) |
|
def | getTaskDict (self, dsname, taskname, what=' *', qual=()) |
|
def | getDSNames (self, dsname) |
|
def | getTaskNames (self, dsname, taskname=None, addWildCards=True) |
|
TaskManager is tool for keeping track of JobRunner jobs.
Definition at line 122 of file TaskManager.py.
def python.TaskManager.TaskManager.__init__ |
( |
|
self, |
|
|
|
connstring = '' , |
|
|
|
createDatabase = False |
|
) |
| |
Constructor. connstring is a connection string specifying either a SQLite file
("sqlite_file:..."), an Oracle database ("oracle://..."), or an authorization file
("auth_file:...") with connection information. If connstring is empty, the connection
information will be taken from TASKDB (if set), or otherwise defaults to
'sqlite_file:taskdata.db'.
Definition at line 168 of file TaskManager.py.
168 def __init__(self, connstring='', createDatabase=False):
169 """Constructor. connstring is a connection string specifying either a SQLite file
170 ("sqlite_file:..."), an Oracle database ("oracle://..."), or an authorization file
171 ("auth_file:...") with connection information. If connstring is empty, the connection
172 information will be taken from TASKDB (if set), or otherwise defaults to
173 'sqlite_file:taskdata.db'."""
176 self.paramstyle =
None
177 self.is_managing_context =
False
179 self.dbtype, self.dbname = self.__class__.parseConnectionInfo(connstring)
181 if self.dbtype ==
'sqlite_file':
183 self.paramstyle =
'qmark'
184 dbexists = os.access(self.dbname, os.F_OK)
185 if dbexists
and createDatabase:
186 raise ValueError (
'SQLite file {} exists already - remove before recreating'.
format(self.dbname))
187 if not (dbexists
or createDatabase):
188 raise ValueError (
'TaskManager database not found (SQLite file {})'.
format(self.dbname))
189 self.dbcon = sqlite3.connect(self.dbname)
191 self._createSQLiteSchema()
192 elif self.dbtype ==
'oracle':
194 self.paramstyle =
'named'
196 self.dbcon = cx_Oracle.connect(self.dbname)
198 print (
'ERROR: First connection attempt to Beam Spot Oracle database failed; will retry in 10s ...')
200 self.dbcon = cx_Oracle.connect(self.dbname)
202 self._createOracleSchema()
204 raise ValueError (
'Unknown database type: {}'.
format(self.dbtype))
def python.TaskManager.TaskManager.execute |
( |
|
self, |
|
|
|
statementParts, |
|
|
|
doCommit = False , |
|
|
|
limit = None |
|
) |
| |
Execute a SQL statement passed as a list or tuple of statement parts, where each
part is either a partial SQL string, or an object of type DbParam specifying a parameter
for the SQL statement. The actual SQL statement is assembled (using the parameter style
of the current database) and executed, and the resulting cursor is returned.
Loosely follows the method discussed in the Python Cookbook.
WARNING: At present, limit doesn't work when ordering rows for Oracle!
Definition at line 313 of file TaskManager.py.
313 def execute(self,statementParts, doCommit=False, limit=None):
314 """Execute a SQL statement passed as a list or tuple of statement parts, where each
315 part is either a partial SQL string, or an object of type DbParam specifying a parameter
316 for the SQL statement. The actual SQL statement is assembled (using the parameter style
317 of the current database) and executed, and the resulting cursor is returned.
318 Loosely follows the method discussed in the Python Cookbook.
319 WARNING: At present, limit doesn't work when ordering rows for Oracle!"""
320 if not self.is_managing_context:
321 print (
'**WARN** TaskManager will keep the database connection open until it is deleted.')
322 print (
'**INFO** TaskManager should generally only be used inside a with statement:')
323 print (
'**INFO** with TaskManager(...) as taskman:')
324 print (
'**INFO** # do something ...')
326 if not statementParts:
328 if isinstance(statementParts,str):
329 raise TypeError (
'Must pass list or tuple to TaskManager.execute')
330 for p
in statementParts:
331 if not (isinstance(p,DbParam)
or isinstance(p,six.string_types)):
332 raise ValueError (
'Can only pass SQL string fragments and DbParam objects in list'
333 'to TaskManager.execute, found %s with "%s"' % (
type(p),
str(p)))
337 if self.paramstyle==
'qmark':
340 for p
in statementParts:
341 if isinstance(p,DbParam):
343 params.append(p.value)
347 if self.paramstyle==
'named':
350 for p
in statementParts:
351 if isinstance(p,DbParam):
352 name =
'p%d' % len(params)
353 sqlParts.append(
':%s' % name)
354 params[name] = p.value
359 raise ValueError (
'Unknown SQL parameter style %s' % self.paramstyle)
361 sql =
' '.
join(sqlParts)
365 if self.dbtype==
'oracle':
367 if 'order by' in sql:
368 sqlParts2 = sql.split(
'order by')
369 sql =
'%s and ROWNUM <= %i order by %s' % (sqlParts2[0],limit,sqlParts2[1])
371 sql +=
' and ROWNUM <= %i' % limit
373 sql +=
' limit %i' % limit
376 print (
'\nExecuting SQL statement: ',sql)
377 print (
' with parameters: ',params)
379 cursor = self.dbcon.
cursor()
381 cursor.execute(sql,params)
384 except Exception
as e:
385 msg =
'\nDatabase error executing SQL statement\n %s\nusing parameters\n %s\n%s' % (sql,params,e)
386 raise TaskManagerDatabaseError (msg)