feat(slurmdb): add JobsService
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
218
internal/slurm/slurmdb_jobs.go
Normal file
218
internal/slurm/slurmdb_jobs.go
Normal file
@@ -0,0 +1,218 @@
|
||||
package slurm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// GetSlurmdbJobsOptions specifies optional query parameters for SlurmdbJobsService.GetJobs.
|
||||
// All 41 parameters correspond to the GET /slurmdb/v0.0.40/jobs endpoint.
|
||||
type GetSlurmdbJobsOptions struct {
|
||||
Account *string `url:"account,omitempty"`
|
||||
Association *string `url:"association,omitempty"`
|
||||
Cluster *string `url:"cluster,omitempty"`
|
||||
Constraints *string `url:"constraints,omitempty"`
|
||||
CpusMax *string `url:"cpus_max,omitempty"`
|
||||
CpusMin *string `url:"cpus_min,omitempty"`
|
||||
SchedulerUnset *string `url:"scheduler_unset,omitempty"`
|
||||
ScheduledOnSubmit *string `url:"scheduled_on_submit,omitempty"`
|
||||
ScheduledByMain *string `url:"scheduled_by_main,omitempty"`
|
||||
ScheduledByBackfill *string `url:"scheduled_by_backfill,omitempty"`
|
||||
JobStarted *string `url:"job_started,omitempty"`
|
||||
ExitCode *string `url:"exit_code,omitempty"`
|
||||
ShowDuplicates *string `url:"show_duplicates,omitempty"`
|
||||
SkipSteps *string `url:"skip_steps,omitempty"`
|
||||
DisableTruncateUsageTime *string `url:"disable_truncate_usage_time,omitempty"`
|
||||
WholeHetjob *string `url:"whole_hetjob,omitempty"`
|
||||
DisableWholeHetjob *string `url:"disable_whole_hetjob,omitempty"`
|
||||
DisableWaitForResult *string `url:"disable_wait_for_result,omitempty"`
|
||||
UsageTimeAsSubmitTime *string `url:"usage_time_as_submit_time,omitempty"`
|
||||
ShowBatchScript *string `url:"show_batch_script,omitempty"`
|
||||
ShowJobEnvironment *string `url:"show_job_environment,omitempty"`
|
||||
Format *string `url:"format,omitempty"`
|
||||
Groups *string `url:"groups,omitempty"`
|
||||
JobName *string `url:"job_name,omitempty"`
|
||||
NodesMax *string `url:"nodes_max,omitempty"`
|
||||
NodesMin *string `url:"nodes_min,omitempty"`
|
||||
Partition *string `url:"partition,omitempty"`
|
||||
Qos *string `url:"qos,omitempty"`
|
||||
Reason *string `url:"reason,omitempty"`
|
||||
Reservation *string `url:"reservation,omitempty"`
|
||||
ReservationID *string `url:"reservation_id,omitempty"`
|
||||
State *string `url:"state,omitempty"`
|
||||
Step *string `url:"step,omitempty"`
|
||||
TimelimitMax *string `url:"timelimit_max,omitempty"`
|
||||
TimelimitMin *string `url:"timelimit_min,omitempty"`
|
||||
EndTime *string `url:"end_time,omitempty"`
|
||||
StartTime *string `url:"start_time,omitempty"`
|
||||
SubmitTime *string `url:"submit_time,omitempty"`
|
||||
Node *string `url:"node,omitempty"`
|
||||
Users *string `url:"users,omitempty"`
|
||||
Wckey *string `url:"wckey,omitempty"`
|
||||
}
|
||||
|
||||
// GetJobs queries the SlurmDBD for jobs matching the given options.
|
||||
func (s *SlurmdbJobsService) GetJobs(ctx context.Context, opts *GetSlurmdbJobsOptions) (*OpenapiSlurmdbdJobsResp, *Response, error) {
|
||||
path := "slurmdb/v0.0.40/jobs"
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
u, parseErr := url.Parse(req.URL.String())
|
||||
if parseErr != nil {
|
||||
return nil, nil, parseErr
|
||||
}
|
||||
q := u.Query()
|
||||
if opts.Account != nil {
|
||||
q.Set("account", *opts.Account)
|
||||
}
|
||||
if opts.Association != nil {
|
||||
q.Set("association", *opts.Association)
|
||||
}
|
||||
if opts.Cluster != nil {
|
||||
q.Set("cluster", *opts.Cluster)
|
||||
}
|
||||
if opts.Constraints != nil {
|
||||
q.Set("constraints", *opts.Constraints)
|
||||
}
|
||||
if opts.CpusMax != nil {
|
||||
q.Set("cpus_max", *opts.CpusMax)
|
||||
}
|
||||
if opts.CpusMin != nil {
|
||||
q.Set("cpus_min", *opts.CpusMin)
|
||||
}
|
||||
if opts.SchedulerUnset != nil {
|
||||
q.Set("scheduler_unset", *opts.SchedulerUnset)
|
||||
}
|
||||
if opts.ScheduledOnSubmit != nil {
|
||||
q.Set("scheduled_on_submit", *opts.ScheduledOnSubmit)
|
||||
}
|
||||
if opts.ScheduledByMain != nil {
|
||||
q.Set("scheduled_by_main", *opts.ScheduledByMain)
|
||||
}
|
||||
if opts.ScheduledByBackfill != nil {
|
||||
q.Set("scheduled_by_backfill", *opts.ScheduledByBackfill)
|
||||
}
|
||||
if opts.JobStarted != nil {
|
||||
q.Set("job_started", *opts.JobStarted)
|
||||
}
|
||||
if opts.ExitCode != nil {
|
||||
q.Set("exit_code", *opts.ExitCode)
|
||||
}
|
||||
if opts.ShowDuplicates != nil {
|
||||
q.Set("show_duplicates", *opts.ShowDuplicates)
|
||||
}
|
||||
if opts.SkipSteps != nil {
|
||||
q.Set("skip_steps", *opts.SkipSteps)
|
||||
}
|
||||
if opts.DisableTruncateUsageTime != nil {
|
||||
q.Set("disable_truncate_usage_time", *opts.DisableTruncateUsageTime)
|
||||
}
|
||||
if opts.WholeHetjob != nil {
|
||||
q.Set("whole_hetjob", *opts.WholeHetjob)
|
||||
}
|
||||
if opts.DisableWholeHetjob != nil {
|
||||
q.Set("disable_whole_hetjob", *opts.DisableWholeHetjob)
|
||||
}
|
||||
if opts.DisableWaitForResult != nil {
|
||||
q.Set("disable_wait_for_result", *opts.DisableWaitForResult)
|
||||
}
|
||||
if opts.UsageTimeAsSubmitTime != nil {
|
||||
q.Set("usage_time_as_submit_time", *opts.UsageTimeAsSubmitTime)
|
||||
}
|
||||
if opts.ShowBatchScript != nil {
|
||||
q.Set("show_batch_script", *opts.ShowBatchScript)
|
||||
}
|
||||
if opts.ShowJobEnvironment != nil {
|
||||
q.Set("show_job_environment", *opts.ShowJobEnvironment)
|
||||
}
|
||||
if opts.Format != nil {
|
||||
q.Set("format", *opts.Format)
|
||||
}
|
||||
if opts.Groups != nil {
|
||||
q.Set("groups", *opts.Groups)
|
||||
}
|
||||
if opts.JobName != nil {
|
||||
q.Set("job_name", *opts.JobName)
|
||||
}
|
||||
if opts.NodesMax != nil {
|
||||
q.Set("nodes_max", *opts.NodesMax)
|
||||
}
|
||||
if opts.NodesMin != nil {
|
||||
q.Set("nodes_min", *opts.NodesMin)
|
||||
}
|
||||
if opts.Partition != nil {
|
||||
q.Set("partition", *opts.Partition)
|
||||
}
|
||||
if opts.Qos != nil {
|
||||
q.Set("qos", *opts.Qos)
|
||||
}
|
||||
if opts.Reason != nil {
|
||||
q.Set("reason", *opts.Reason)
|
||||
}
|
||||
if opts.Reservation != nil {
|
||||
q.Set("reservation", *opts.Reservation)
|
||||
}
|
||||
if opts.ReservationID != nil {
|
||||
q.Set("reservation_id", *opts.ReservationID)
|
||||
}
|
||||
if opts.State != nil {
|
||||
q.Set("state", *opts.State)
|
||||
}
|
||||
if opts.Step != nil {
|
||||
q.Set("step", *opts.Step)
|
||||
}
|
||||
if opts.TimelimitMax != nil {
|
||||
q.Set("timelimit_max", *opts.TimelimitMax)
|
||||
}
|
||||
if opts.TimelimitMin != nil {
|
||||
q.Set("timelimit_min", *opts.TimelimitMin)
|
||||
}
|
||||
if opts.EndTime != nil {
|
||||
q.Set("end_time", *opts.EndTime)
|
||||
}
|
||||
if opts.StartTime != nil {
|
||||
q.Set("start_time", *opts.StartTime)
|
||||
}
|
||||
if opts.SubmitTime != nil {
|
||||
q.Set("submit_time", *opts.SubmitTime)
|
||||
}
|
||||
if opts.Node != nil {
|
||||
q.Set("node", *opts.Node)
|
||||
}
|
||||
if opts.Users != nil {
|
||||
q.Set("users", *opts.Users)
|
||||
}
|
||||
if opts.Wckey != nil {
|
||||
q.Set("wckey", *opts.Wckey)
|
||||
}
|
||||
u.RawQuery = q.Encode()
|
||||
req.URL = u
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdJobsResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
|
||||
// GetJob retrieves info for a specific job from SlurmDBD.
|
||||
func (s *SlurmdbJobsService) GetJob(ctx context.Context, jobID string) (*OpenapiSlurmdbdJobsResp, *Response, error) {
|
||||
path := fmt.Sprintf("slurmdb/v0.0.40/job/%s", jobID)
|
||||
req, err := s.client.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var result OpenapiSlurmdbdJobsResp
|
||||
resp, err := s.client.Do(ctx, req, &result)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return &result, resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user