|
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 120 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 166 of file TaskManager.py.
166 def __init__(self, connstring='', createDatabase=False):
167 """Constructor. connstring is a connection string specifying either a SQLite file
168 ("sqlite_file:..."), an Oracle database ("oracle://..."), or an authorization file
169 ("auth_file:...") with connection information. If connstring is empty, the connection
170 information will be taken from TASKDB (if set), or otherwise defaults to
171 'sqlite_file:taskdata.db'."""
174 self.paramstyle =
None
175 self.is_managing_context =
False
177 self.dbtype, self.dbname = self.__class__.parseConnectionInfo(connstring)
179 if self.dbtype ==
'sqlite_file':
181 self.paramstyle =
'qmark'
182 dbexists = os.access(self.dbname, os.F_OK)
183 if dbexists
and createDatabase:
184 raise ValueError (
'SQLite file {} exists already - remove before recreating'.
format(self.dbname))
185 if not (dbexists
or createDatabase):
186 raise ValueError (
'TaskManager database not found (SQLite file {})'.
format(self.dbname))
187 self.dbcon = sqlite3.connect(self.dbname)
189 self._createSQLiteSchema()
190 elif self.dbtype ==
'oracle':
192 self.paramstyle =
'named'
194 self.dbcon = cx_Oracle.connect(self.dbname)
196 print (
'ERROR: First connection attempt to Beam Spot Oracle database failed; will retry in 10s ...')
198 self.dbcon = cx_Oracle.connect(self.dbname)
200 self._createOracleSchema()
202 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 311 of file TaskManager.py.
311 def execute(self,statementParts, doCommit=False, limit=None):
312 """Execute a SQL statement passed as a list or tuple of statement parts, where each
313 part is either a partial SQL string, or an object of type DbParam specifying a parameter
314 for the SQL statement. The actual SQL statement is assembled (using the parameter style
315 of the current database) and executed, and the resulting cursor is returned.
316 Loosely follows the method discussed in the Python Cookbook.
317 WARNING: At present, limit doesn't work when ordering rows for Oracle!"""
318 if not self.is_managing_context:
319 print (
'**WARN** TaskManager will keep the database connection open until it is deleted.')
320 print (
'**INFO** TaskManager should generally only be used inside a with statement:')
321 print (
'**INFO** with TaskManager(...) as taskman:')
322 print (
'**INFO** # do something ...')
324 if not statementParts:
326 if isinstance(statementParts,str):
327 raise TypeError (
'Must pass list or tuple to TaskManager.execute')
328 for p
in statementParts:
329 if not (isinstance(p,DbParam)
or isinstance(p,str)):
330 raise ValueError (
'Can only pass SQL string fragments and DbParam objects in list'
331 'to TaskManager.execute, found %s with "%s"' % (
type(p),
str(p)))
335 if self.paramstyle==
'qmark':
338 for p
in statementParts:
339 if isinstance(p,DbParam):
341 params.append(p.value)
345 if self.paramstyle==
'named':
348 for p
in statementParts:
349 if isinstance(p,DbParam):
350 name =
'p%d' % len(params)
351 sqlParts.append(
':%s' % name)
352 params[name] = p.value
357 raise ValueError (
'Unknown SQL parameter style %s' % self.paramstyle)
359 sql =
' '.
join(sqlParts)
363 if self.dbtype==
'oracle':
365 if 'order by' in sql:
366 sqlParts2 = sql.split(
'order by')
367 sql =
'%s and ROWNUM <= %i order by %s' % (sqlParts2[0],limit,sqlParts2[1])
369 sql +=
' and ROWNUM <= %i' % limit
371 sql +=
' limit %i' % limit
374 print (
'\nExecuting SQL statement: ',sql)
375 print (
' with parameters: ',params)
377 cursor = self.dbcon.
cursor()
379 cursor.execute(sql,params)
382 except Exception
as e:
383 msg =
'\nDatabase error executing SQL statement\n %s\nusing parameters\n %s\n%s' % (sql,params,e)
384 raise TaskManagerDatabaseError (msg)