Skip to content

Commit cd3742f

Browse files
committed
Backport: Allow db job modification and some fixes (#297)
- Ability to modify Database Jobs - New attributes for a Database Job: - extra - failed_node - Now possible to initialize a pyslurm.db.Jobs collection with existing job ids or pyslurm.db.Job objects - Fixes a problem that prevented loading specific Jobs from the Database if the following two conditions were met: - no start/end time was specified - the Job was older than a day - create a _get_exit_code helper function to reduce duplicate code in various places when checking for exit-code or exit-signal of a Job or JobStep
1 parent f5933ad commit cd3742f

File tree

8 files changed

+301
-55
lines changed

8 files changed

+301
-55
lines changed

pyslurm/core/job/job.pyx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ from pyslurm.utils.helpers import (
4848
_getpwall_to_dict,
4949
instance_to_dict,
5050
_sum_prop,
51+
_get_exit_code,
5152
)
5253

5354

@@ -785,35 +786,23 @@ cdef class Job:
785786

786787
@property
787788
def derived_exit_code(self):
788-
if (self.ptr.derived_ec == slurm.NO_VAL
789-
or not WIFEXITED(self.ptr.derived_ec)):
790-
return None
791-
792-
return WEXITSTATUS(self.ptr.derived_ec)
789+
ec, _ = _get_exit_code(self.ptr.derived_ec)
790+
return ec
793791

794792
@property
795793
def derived_exit_code_signal(self):
796-
if (self.ptr.derived_ec == slurm.NO_VAL
797-
or not WIFSIGNALED(self.ptr.derived_ec)):
798-
return None
799-
800-
return WTERMSIG(self.ptr.derived_ec)
794+
_, sig = _get_exit_code(self.ptr.derived_ec)
795+
return sig
801796

802797
@property
803798
def exit_code(self):
804-
if (self.ptr.exit_code == slurm.NO_VAL
805-
or not WIFEXITED(self.ptr.exit_code)):
806-
return None
807-
808-
return WEXITSTATUS(self.ptr.exit_code)
799+
ec, _ = _get_exit_code(self.ptr.exit_code)
800+
return ec
809801

810802
@property
811803
def exit_code_signal(self):
812-
if (self.ptr.exit_code == slurm.NO_VAL
813-
or not WIFSIGNALED(self.ptr.exit_code)):
814-
return None
815-
816-
return WTERMSIG(self.ptr.exit_code)
804+
_, sig = _get_exit_code(self.ptr.exit_code)
805+
return sig
817806

818807
@property
819808
def batch_constraints(self):

pyslurm/db/job.pxd

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ from pyslurm.slurm cimport (
3939
slurmdb_job_cond_def_start_end,
4040
slurm_job_state_string,
4141
slurm_job_reason_string,
42+
slurmdb_create_job_rec,
43+
slurmdb_job_modify,
4244
)
4345
from pyslurm.db.util cimport (
4446
SlurmList,
@@ -162,8 +164,17 @@ cdef class Job:
162164
job_id (int, optional=0):
163165
An Integer representing a Job-ID.
164166
165-
Raises:
166-
MemoryError: If malloc fails to allocate memory.
167+
Other Parameters:
168+
admin_comment (str):
169+
Admin comment for the Job.
170+
comment (str):
171+
Comment for the Job
172+
wckey (str):
173+
Name of the WCKey for this Job
174+
derived_exit_code (int):
175+
Highest exit code of all the Job steps
176+
extra (str):
177+
Arbitrary string that can be stored with a Job.
167178
168179
Attributes:
169180
steps (pyslurm.db.JobSteps):
@@ -209,10 +220,14 @@ cdef class Job:
209220
When the Job became eligible to run, as a unix timestamp
210221
end_time (int):
211222
When the Job ended, as a unix timestamp
223+
extra (str):
224+
Arbitrary string that can be stored with a Job.
212225
exit_code (int):
213226
Exit code of the job script or salloc.
214227
exit_code_signal (int):
215228
Signal of the exit code for this Job.
229+
failed_node (str):
230+
Name of the failed node that caused the job to get killed.
216231
group_id (int):
217232
ID of the group for this Job
218233
group_name (str):

0 commit comments

Comments
 (0)