feat(service): map additional Slurm SDK fields and fix ExitCode/Default bugs

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-10 11:12:51 +08:00
parent 85901fe18a
commit 824d9e816f
2 changed files with 146 additions and 13 deletions

View File

@@ -282,6 +282,14 @@ func strToPtrOrNil(s string) *string {
return &s
}
func mapUint32NoValToInt32(v *slurm.Uint32NoVal) *int32 {
if v != nil && v.Number != nil {
n := int32(*v.Number)
return &n
}
return nil
}
// mapJobInfo maps SDK JobInfo to API JobResponse.
func mapJobInfo(ji *slurm.JobInfo) model.JobResponse {
resp := model.JobResponse{}
@@ -295,6 +303,17 @@ func mapJobInfo(ji *slurm.JobInfo) model.JobResponse {
if ji.Partition != nil {
resp.Partition = *ji.Partition
}
resp.Account = derefStr(ji.Account)
resp.User = derefStr(ji.UserName)
resp.Cluster = derefStr(ji.Cluster)
resp.QOS = derefStr(ji.Qos)
resp.Priority = mapUint32NoValToInt32(ji.Priority)
resp.TimeLimit = uint32NoValString(ji.TimeLimit)
resp.StateReason = derefStr(ji.StateReason)
resp.Cpus = mapUint32NoValToInt32(ji.Cpus)
resp.Tasks = mapUint32NoValToInt32(ji.Tasks)
resp.NodeCount = mapUint32NoValToInt32(ji.NodeCount)
resp.BatchHost = derefStr(ji.BatchHost)
if ji.SubmitTime != nil && ji.SubmitTime.Number != nil {
resp.SubmitTime = ji.SubmitTime.Number
}
@@ -311,6 +330,13 @@ func mapJobInfo(ji *slurm.JobInfo) model.JobResponse {
if ji.Nodes != nil {
resp.Nodes = *ji.Nodes
}
resp.StdOut = derefStr(ji.StandardOutput)
resp.StdErr = derefStr(ji.StandardError)
resp.StdIn = derefStr(ji.StandardInput)
resp.WorkDir = derefStr(ji.CurrentWorkingDirectory)
resp.Command = derefStr(ji.Command)
resp.ArrayJobID = mapUint32NoValToInt32(ji.ArrayJobID)
resp.ArrayTaskID = mapUint32NoValToInt32(ji.ArrayTaskID)
return resp
}
@@ -325,11 +351,20 @@ func mapSlurmdbJob(j *slurm.Job) model.JobResponse {
}
if j.State != nil {
resp.State = j.State.Current
resp.StateReason = derefStr(j.State.Reason)
}
if j.Partition != nil {
resp.Partition = *j.Partition
}
resp.Account = derefStr(j.Account)
if j.User != nil {
resp.User = *j.User
}
resp.Cluster = derefStr(j.Cluster)
resp.QOS = derefStr(j.Qos)
resp.Priority = mapUint32NoValToInt32(j.Priority)
if j.Time != nil {
resp.TimeLimit = uint32NoValString(j.Time.Limit)
if j.Time.Submission != nil {
resp.SubmitTime = j.Time.Submission
}
@@ -340,8 +375,19 @@ func mapSlurmdbJob(j *slurm.Job) model.JobResponse {
resp.EndTime = j.Time.End
}
}
if j.ExitCode != nil && j.ExitCode.ReturnCode != nil && j.ExitCode.ReturnCode.Number != nil {
code := int32(*j.ExitCode.ReturnCode.Number)
resp.ExitCode = &code
}
if j.Nodes != nil {
resp.Nodes = *j.Nodes
}
if j.Required != nil {
resp.Cpus = j.Required.CPUs
}
if j.AllocationNodes != nil {
resp.NodeCount = j.AllocationNodes
}
resp.WorkDir = derefStr(j.WorkingDirectory)
return resp
}