File indexing completed on 2026-04-10 08:39:07
0001 import optparse
0002 import sys
0003
0004 from pandaserver.userinterface import Client
0005
0006 option_parser = optparse.OptionParser(conflict_handler="resolve")
0007 option_parser.add_option(
0008 "-9",
0009 action="store_const",
0010 const=True,
0011 dest="forceKill",
0012 default=False,
0013 help="kill jobs before next heartbeat is coming",
0014 )
0015 option_parser.add_option("--codeV", action="store", dest="codeV", default=None, help="kill code")
0016 option_parser.add_option(
0017 "--jobSubStatus",
0018 action="store",
0019 dest="jobSubStatus",
0020 default=None,
0021 help="set job sub status if any",
0022 )
0023 option_parser.add_option(
0024 "--killOwnProdJobs",
0025 action="store_const",
0026 const=True,
0027 dest="killOwnProdJobs",
0028 default=False,
0029 help="kill own production jobs without a production role",
0030 )
0031 option_parser.add_option(
0032 "--killUserJobs",
0033 action="store_const",
0034 const=True,
0035 dest="killUserJobs",
0036 default=False,
0037 help="kill user jobs using a production role",
0038 )
0039 option_parser.add_option(
0040 "--keepUnmerged",
0041 action="store_const",
0042 const=True,
0043 dest="keepUnmerged",
0044 default=False,
0045 help="generate a new job after kiliing, to keep unmerged events",
0046 )
0047 options, args = option_parser.parse_args()
0048
0049 codeV = None
0050 useMailAsIDV = False
0051
0052 if options.forceKill:
0053 if options.killUserJobs:
0054 codeV = 99
0055 else:
0056 codeV = 9
0057 elif options.killUserJobs:
0058 codeV = 91
0059 else:
0060 try:
0061 codeV = int(options.codeV)
0062 except Exception:
0063 pass
0064 if options.killOwnProdJobs:
0065 useMailAsIDV = True
0066
0067 if len(args) == 1:
0068 job_id = int(args[0])
0069 ret = Client.kill_jobs([job_id], code=codeV, keep_unmerged=options.keepUnmerged, job_sub_status=options.jobSubStatus)
0070 else:
0071 job_id_start = int(args[0])
0072 job_id_end = int(args[1])
0073 if job_id_start > job_id_end:
0074 print(f"{job_id_end} is less than {job_id_start}")
0075 sys.exit(1)
0076
0077 ret = Client.kill_jobs(range(job_id_start, job_id_end + 1), code=codeV, keep_unmerged=options.keepUnmerged, job_sub_status=options.jobSubStatus)
0078
0079 print(ret)