Skip to content

Commit a614720

Browse files
Maurice YapGitHub Enterprise
authored andcommitted
Add cancel user to Job object
This adds the user who cancelled a job to the job object, along with a new column in the Lookout DB.
1 parent ae9314b commit a614720

File tree

19 files changed

+189
-101
lines changed

19 files changed

+189
-101
lines changed

internal/lookoutui/src/models/lookoutModels.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export type Job = {
122122
lastActiveRunId?: string
123123
lastTransitionTime: string
124124
cancelReason?: string
125+
cancelUser?: string
125126
node?: string
126127
cluster?: string
127128
exitCode?: number

internal/lookoutv2/conversions/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func ToSwaggerJob(job *model.Job) *models.Job {
3737
State: job.State,
3838
Submitted: strfmt.DateTime(job.Submitted),
3939
CancelReason: job.CancelReason,
40+
CancelUser: job.CancelUser,
4041
Node: job.Node,
4142
Cluster: job.Cluster,
4243
ExitCode: job.ExitCode,

internal/lookoutv2/gen/models/job.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lookoutv2/gen/restapi/embedded_spec.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lookoutv2/model/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Job struct {
4040
State string
4141
Submitted time.Time
4242
CancelReason *string
43+
CancelUser *string
4344
Node *string
4445
Cluster string
4546
ExitCode *int32

internal/lookoutv2/repository/getjobs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type jobRow struct {
4747
priorityClass sql.NullString
4848
latestRunId sql.NullString
4949
cancelReason sql.NullString
50+
cancelUser sql.NullString
5051
}
5152

5253
func NewSqlGetJobsRepository(db *pgxpool.Pool) *SqlGetJobsRepository {
@@ -102,6 +103,7 @@ func (r *SqlGetJobsRepository) getJobs(ctx *armadacontext.Context, filters []*mo
102103
&row.priorityClass,
103104
&row.latestRunId,
104105
&row.cancelReason,
106+
&row.cancelUser,
105107
&annotations,
106108
&runs,
107109
); err != nil {
@@ -170,5 +172,6 @@ func jobRowToModel(row *jobRow) *model.Job {
170172
State: string(lookout.JobStateMap[row.state]),
171173
Submitted: row.submitted,
172174
CancelReason: database.ParseNullString(row.cancelReason),
175+
CancelUser: database.ParseNullString(row.cancelUser),
173176
}
174177
}

internal/lookoutv2/repository/getjobs_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import (
2424
)
2525

2626
const (
27-
jobId = "01f3j0g1md4qx7z5qb148qnh4d"
28-
queue = "queue-1"
29-
jobSet = "job-set-1"
30-
cluster = "cluster-1"
31-
owner = "user-1"
32-
namespace = "namespace-1"
33-
priority = 12
27+
jobId = "01f3j0g1md4qx7z5qb148qnh4d"
28+
queue = "queue-1"
29+
jobSet = "job-set-1"
30+
cluster = "cluster-1"
31+
owner = "user-1"
32+
cancelUser = "canceluser"
33+
namespace = "namespace-1"
34+
priority = 12
3435

3536
userAnnotationPrefix = "armadaproject.io/"
3637
)
@@ -1978,13 +1979,13 @@ func TestGetJobsActiveJobSet(t *testing.T) {
19781979

19791980
inactiveJobSet1 := NewJobSimulatorWithClock(converter, store, testClock).
19801981
Submit("queue-1", "job-set-1", owner, namespace, baseTime, &JobOptions{}).
1981-
Cancelled(baseTime.Add(1 * time.Minute)).
1982+
Cancelled(baseTime.Add(1*time.Minute), cancelUser).
19821983
Build().
19831984
Job()
19841985

19851986
NewJobSimulatorWithClock(converter, store, testClock).
19861987
Submit("queue-2", "job-set-2", owner, namespace, baseTime, &JobOptions{}).
1987-
Cancelled(baseTime.Add(1 * time.Minute)).
1988+
Cancelled(baseTime.Add(1*time.Minute), cancelUser).
19881989
Build().
19891990
Job()
19901991

internal/lookoutv2/repository/querybuilder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (qb *QueryBuilder) GetJobs(
108108
selected_jobs.priority_class,
109109
selected_jobs.latest_run_id,
110110
selected_jobs.cancel_reason,
111+
selected_jobs.cancel_user,
111112
selected_jobs.annotations,
112113
selected_runs.runs
113114
FROM (
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE job ADD COLUMN cancel_user varchar(512) NULL;

internal/lookoutv2/swagger.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
swagger: '2.0'
2+
swagger: "2.0"
33
info:
44
version: 2.0.0
55
title: Lookout v2 API
@@ -116,6 +116,9 @@ definitions:
116116
cancelReason:
117117
type: string
118118
x-nullable: true
119+
cancelUser:
120+
type: string
121+
x-nullable: true
119122
node:
120123
type: string
121124
x-nullable: true

0 commit comments

Comments
 (0)