Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:07

0001 import optparse
0002 import time
0003 
0004 # password
0005 from pandaserver.config import panda_config
0006 from pandaserver.taskbuffer.OraDBProxy import DBProxy
0007 from pandaserver.userinterface import Client
0008 
0009 option_parser = optparse.OptionParser(conflict_handler="resolve")
0010 option_parser.add_option(
0011     "-9",
0012     action="store_const",
0013     const=True,
0014     dest="forceKill",
0015     default=False,
0016     help="kill jobs even if they are still running",
0017 )
0018 option_parser.add_option(
0019     "--noRunning",
0020     action="store_const",
0021     const=True,
0022     dest="noRunning",
0023     default=True,
0024     help="kill jobs if they are not in running or transferring (ON by default)",
0025 )
0026 option_parser.add_option(
0027     "--killAny",
0028     action="store_const",
0029     const=True,
0030     dest="killAny",
0031     default=False,
0032     help="kill jobs in any status",
0033 )
0034 option_parser.add_option(
0035     "--prodSourceLabel",
0036     action="store",
0037     dest="prodSourceLabel",
0038     default="managed",
0039     help="prodSourceLabel",
0040 )
0041 
0042 options, args = option_parser.parse_args()
0043 
0044 proxyS = DBProxy()
0045 proxyS.connect(panda_config.dbhost, panda_config.dbpasswd, panda_config.dbuser, panda_config.dbname)
0046 
0047 jobs = []
0048 
0049 varMap = {}
0050 varMap[":prodSourceLabel"] = options.prodSourceLabel
0051 varMap[":taskID"] = args[0]
0052 if not options.noRunning or options.killAny:
0053     sql = "SELECT PandaID FROM %s WHERE prodSourceLabel=:prodSourceLabel AND taskID=:taskID ORDER BY PandaID"
0054 else:
0055     sql = "SELECT PandaID FROM %s WHERE prodSourceLabel=:prodSourceLabel AND taskID=:taskID AND NOT jobStatus IN (:js1,:js2,:js3) ORDER BY PandaID"
0056     varMap[":js1"] = "running"
0057     varMap[":js2"] = "transferring"
0058     varMap[":js3"] = "holding"
0059 for table in [
0060     "ATLAS_PANDA.jobsActive4",
0061     "ATLAS_PANDA.jobsDefined4",
0062 ]:
0063     status, res = proxyS.querySQLS(sql % table, varMap)
0064     if res is not None:
0065         for (id,) in res:
0066             if id not in jobs:
0067                 jobs.append(id)
0068 
0069 print(f"The number of jobs to be killed for prodSourceLabel={options.prodSourceLabel} taskID={args[0]}: {len(jobs)}")
0070 if len(jobs):
0071     nJob = 100
0072     iJob = 0
0073     while iJob < len(jobs):
0074         print(f"kill {str(jobs[iJob:iJob + nJob])}")
0075         if options.forceKill:
0076             Client.kill_jobs(jobs[iJob : iJob + nJob], 9)
0077         else:
0078             Client.kill_jobs(jobs[iJob : iJob + nJob])
0079         iJob += nJob
0080         time.sleep(1)