Skip to content

add examples for query multiple jobs info #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions examples/get_jobs_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from pythonlsf import lsf
import sys

def get_job_info(list) :
if lsf.lsb_init("test") > 0:
print("failed to initialize")
return
if len(list) == 0 :
print("no valid job id given")
return
print("request below job's info: {}".format(list))
clusterName = lsf.ls_getclustername()
print("retrieve cluster name : {}".format(clusterName))
query = "jobIds=("
for l in list:
query += l +","
query = query[:-1]
query += ")jobSouceClusterNames=("
for i in range(len(list)):
query += clusterName + ","
query = query[:-1]
query += ") options=" + str(lsf.ALL_JOB) + " "

jobQuery = lsf.jobInfoQuery()
jobQuery.nCols = 10
jobQuery.colIndexs = lsf.buildQueryColIndexs()

jobQuery.query = query
jobQuery.submitExt = lsf.submit_ext()
more = lsf.new_intp()
print("request: {}".format(jobQuery.query))
jobInfoPtr = lsf.jobInfoHeadExt()
jobInfoPtr = lsf.lsb_queryjobinfo_ext_2(jobQuery, clusterName)
foundJob = False
if jobInfoPtr != None :
if jobInfoPtr.jobInfoHead != None :
foundJob = True
if not foundJob :
print("faild to query jobs")
else :
print("found job number : {}".format(jobInfoPtr.jobInfoHead.numJobs))
if jobInfoPtr.jobInfoHead.numJobs > 0 :
job = lsf.jobInfoEnt()
job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)
if job == None:
print("no job found")
while job != None:
print("job <{}> from user ({}) status is {}".format(lsf.lsb_jobid2str(job.jobId),job.user, job.status))
job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)


if __name__ == "__main__":
joblist = []
if len(sys.argv) < 2:
joblist = ['0']
else:
for jobid in sys.argv[1:]:
joblist.append(jobid)
joblist = ['3530','3531']
get_job_info(joblist)
14 changes: 14 additions & 0 deletions pythonlsf/lsf.i
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,20 @@ PyObject * get_pids_from_stream(struct jRusage * jrusage) {
return result;
}

long * buildQueryColIndexs() {
long * colIndexs = NULL;
int i = 0;

colIndexs = calloc(113, sizeof(long));
for (i= 0; i < 113; i++) {
colIndexs[i] = i;
}
colIndexs[1] = 2;
colIndexs[2] = 1;
colIndexs[9] = 10;
return colIndexs;
}

PyObject * get_host_info_all() {
struct hostInfoEnt *hostinfo;
char **hosts = NULL;
Expand Down