Skip to content

Commit 429749f

Browse files
committed
Specify jobids when getting all jobs from slurmdb.
- Add startime and endtime to job conditions
1 parent 4a7eeda commit 429749f

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pyslurm/pyslurm.pyx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5546,7 +5546,18 @@ cdef class slurmdb_jobs:
55465546
def get(self, jobids=[], starttime=0, endtime=0):
55475547
u"""Get Slurmdb information about some jobs.
55485548
5549-
:param jobids: Ids of the jobs to search. [] for any id
5549+
Input formats for start and end times:
5550+
* today or tomorrow
5551+
* midnight, noon, teatime (4PM)
5552+
* HH:MM [AM|PM]
5553+
* MMDDYY or MM/DD/YY or MM.DD.YY
5554+
* YYYY-MM-DD[THH[:MM[:SS]]]
5555+
* now + count [minutes | hours | days | weeks]
5556+
*
5557+
Invalid time input results in message to stderr and return value of
5558+
zero.
5559+
5560+
:param jobids: Ids of the jobs to search. Defaults to all jobs.
55505561
:param starttime: Select jobs eligible after this timestamp
55515562
:param endtime: Select jobs eligible before this timestamp
55525563
:returns: Dictionary whose key is the JOBS ID
@@ -5558,11 +5569,32 @@ cdef class slurmdb_jobs:
55585569
cdef:
55595570
int i = 0
55605571
int listNum = 0
5561-
dict J_dict = {}
55625572
int apiError = 0
5573+
dict J_dict = {}
55635574
slurm.List JOBSList
55645575
slurm.ListIterator iters = NULL
55655576

5577+
if jobids:
5578+
self.job_cond.step_list = slurm.slurm_list_create(NULL)
5579+
for _jobid in jobids:
5580+
if isinstance(_jobid, int) or isinstance(_jobid, long):
5581+
_jobid = str(_jobid).encode("UTF-8")
5582+
else:
5583+
_jobid = _jobid.encode("UTF-8")
5584+
slurm.slurm_addto_step_list(self.job_cond.step_list, _jobid)
5585+
5586+
if starttime:
5587+
self.job_cond.usage_start = slurm.slurm_parse_time(starttime, 1)
5588+
errno = slurm.slurm_get_errno()
5589+
if errno == slurm.ESLURM_INVALID_TIME_VALUE:
5590+
raise ValueError(slurm.slurm_strerror(errno), errno)
5591+
5592+
if endtime:
5593+
self.job_cond.usage_end = slurm.slurm_parse_time(endtime, 1)
5594+
errno = slurm.slurm_get_errno()
5595+
if errno == slurm.ESLURM_INVALID_TIME_VALUE:
5596+
raise ValueError(slurm.slurm_strerror(errno), errno)
5597+
55665598
JOBSList = slurm.slurmdb_jobs_get(self.db_conn, self.job_cond)
55675599

55685600
if JOBSList is NULL:

pyslurm/slurm.pxd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ cdef extern from 'slurm/slurm_errno.h' nogil:
116116
enum:
117117
ESLURM_ERROR_ON_DESC_TO_RECORD_COPY
118118
ESLURM_NODES_BUSY
119+
ESLURM_INVALID_TIME_VALUE
119120

120121
cdef extern char * slurm_strerror (int)
121122
cdef void slurm_seterrno (int)
@@ -2837,3 +2838,12 @@ cdef extern int slurm_env_array_overwrite(char ***array_ptr, const_char_ptr name
28372838
cdef extern int slurm_env_array_overwrite_fmt(char ***array_ptr, const_char_ptr name, const_char_ptr value_fmt, ...)
28382839

28392840
cdef extern char *slurm_get_checkpoint_dir()
2841+
cdef extern void slurm_sprint_cpu_bind_type(char *string, cpu_bind_type_t cpu_bind_type)
2842+
cdef extern void slurm_destroy_char(void *object)
2843+
cdef extern int slurm_addto_step_list(List step_list, char *names)
2844+
cdef extern time_t slurm_parse_time(char *time_str, int past)
2845+
cdef extern int slurm_time_str2mins(const_char_ptr string)
2846+
cdef extern int slurm_time_str2secs(const_char_ptr string)
2847+
cdef extern void slurm_secs2time_str(time_t time, char *string, int size)
2848+
cdef extern void slurm_mins2time_str(uint32_t time, char *string, int size)
2849+
cdef extern char *slurm_mon_abbr(int mon)

0 commit comments

Comments
 (0)