PR feedback

Signed-off-by: Richard Inskip <richard.inskip@depop.com>
This commit is contained in:
Richard Inskip 2021-07-27 17:33:36 +01:00
parent 9ed03cace7
commit a974edd3b2
7 changed files with 50 additions and 60 deletions

View File

@ -126,8 +126,7 @@ var jobsQuery = psql.Select(
"j.disable_manual_trigger",
"j.paused_by",
"j.paused_at").
From("jobs j").
LeftJoin("pipelines p ON j.pipeline_id = p.id").
From("jobs j, pipelines p").
LeftJoin("teams t ON p.team_id = t.id").
Where(sq.Expr("j.pipeline_id = p.id"))
@ -147,8 +146,8 @@ type job struct {
id int
name string
paused bool
pausedBy sql.NullString
pausedAt sql.NullTime
pausedBy string
pausedAt time.Time
public bool
firstLoggedBuildID int
teamID int
@ -210,6 +209,8 @@ func (jobs Jobs) Configs() (atc.JobConfigs, error) {
func (j *job) ID() int { return j.id }
func (j *job) Name() string { return j.name }
func (j *job) Paused() bool { return j.paused }
func (j *job) PausedAt() time.Time { return j.pausedAt }
func (j *job) PausedBy() string { return j.pausedBy }
func (j *job) Public() bool { return j.public }
func (j *job) FirstLoggedBuildID() int { return j.firstLoggedBuildID }
func (j *job) TeamID() int { return j.teamID }
@ -469,22 +470,6 @@ func (j *job) Unpause() error {
return nil
}
func (j *job) PausedAt() time.Time {
if j.pausedAt.Valid {
return j.pausedAt.Time
} else {
return time.Time{}
}
}
func (j *job) PausedBy() string {
if j.pausedBy.Valid {
return j.pausedBy.String
} else {
return ""
}
}
func (j *job) FinishedAndNextBuild() (Build, Build, error) {
tx, err := j.conn.Begin()
if err != nil {
@ -1408,8 +1393,8 @@ func (j *job) isPipelineOrJobPaused(tx Tx) (bool, error) {
var paused bool
err := psql.Select("paused").
From("pipelines p").
Where(sq.Eq{"p.id": j.pipelineID}).
From("pipelines").
Where(sq.Eq{"id": j.pipelineID}).
RunWith(tx).
QueryRow().
Scan(&paused)
@ -1425,9 +1410,11 @@ func scanJob(j *job, row scannable) error {
config sql.NullString
nonce sql.NullString
pipelineInstanceVars sql.NullString
pausedBy sql.NullString
pausedAt sql.NullTime
)
err := row.Scan(&j.id, &j.name, &config, &j.paused, &j.public, &j.firstLoggedBuildID, &j.pipelineID, &j.pipelineName, &pipelineInstanceVars, &j.teamID, &j.teamName, &nonce, pq.Array(&j.tags), &j.hasNewInputs, &j.scheduleRequestedTime, &j.maxInFlight, &j.disableManualTrigger, &j.pausedBy, &j.pausedAt)
err := row.Scan(&j.id, &j.name, &config, &j.paused, &j.public, &j.firstLoggedBuildID, &j.pipelineID, &j.pipelineName, &pipelineInstanceVars, &j.teamID, &j.teamName, &nonce, pq.Array(&j.tags), &j.hasNewInputs, &j.scheduleRequestedTime, &j.maxInFlight, &j.disableManualTrigger, &pausedBy, &pausedAt)
if err != nil {
return err
}
@ -1447,6 +1434,14 @@ func scanJob(j *job, row scannable) error {
}
}
if pausedBy.Valid {
j.pausedBy = pausedBy.String
}
if pausedAt.Valid {
j.pausedAt = pausedAt.Time
}
return nil
}

View File

@ -191,7 +191,7 @@ var _ = Describe("Job", func() {
})
})
Context("when pausing with a request", func() {
Context("when pausing with a user", func() {
BeforeEach(func() {
initialRequestedTime = job.ScheduleRequestedTime()

View File

@ -1,3 +1,3 @@
ALTER TABLE jobs
ADD COLUMN paused_by text DEFAULT NULL,
ADD COLUMN paused_at timestamptz DEFAULT NULL;
ADD COLUMN paused_by text,
ADD COLUMN paused_at timestamptz;

View File

@ -1,3 +1,3 @@
ALTER TABLE pipelines
ADD COLUMN paused_by text DEFAULT NULL,
ADD COLUMN paused_at timestamptz DEFAULT NULL;
ADD COLUMN paused_by text,
ADD COLUMN paused_at timestamptz;

View File

@ -137,8 +137,8 @@ type pipeline struct {
display *atc.DisplayConfig
configVersion ConfigVersion
paused bool
pausedBy sql.NullString
pausedAt sql.NullTime
pausedBy string
pausedAt time.Time
public bool
archived bool
lastUpdated time.Time
@ -179,29 +179,30 @@ func newPipeline(conn Conn, lockFactory lock.LockFactory) *pipeline {
}
}
func (p *pipeline) ID() int { return p.id }
func (p *pipeline) Name() string { return p.name }
func (p *pipeline) TeamID() int { return p.teamID }
func (p *pipeline) TeamName() string { return p.teamName }
func (p *pipeline) ParentJobID() int { return p.parentJobID }
func (p *pipeline) ParentBuildID() int { return p.parentBuildID }
func (p *pipeline) InstanceVars() atc.InstanceVars { return p.instanceVars }
func (p *pipeline) Groups() atc.GroupConfigs { return p.groups }
func (p *pipeline) ID() int { return p.id }
func (p *pipeline) Name() string { return p.name }
func (p *pipeline) TeamID() int { return p.teamID }
func (p *pipeline) TeamName() string { return p.teamName }
func (p *pipeline) ParentJobID() int { return p.parentJobID }
func (p *pipeline) ParentBuildID() int { return p.parentBuildID }
func (p *pipeline) InstanceVars() atc.InstanceVars { return p.instanceVars }
func (p *pipeline) Groups() atc.GroupConfigs { return p.groups }
func (p *pipeline) VarSources() atc.VarSourceConfigs { return p.varSources }
func (p *pipeline) Display() *atc.DisplayConfig { return p.display }
func (p *pipeline) ConfigVersion() ConfigVersion { return p.configVersion }
func (p *pipeline) Public() bool { return p.public }
func (p *pipeline) Paused() bool { return p.paused }
func (p *pipeline) PausedAt() time.Time { return p.pausedAt }
func (p *pipeline) PausedBy() string { return p.pausedBy }
func (p *pipeline) Archived() bool { return p.archived }
func (p *pipeline) LastUpdated() time.Time { return p.lastUpdated }
func (p *pipeline) CheckPaused() (bool, error) {
var paused bool
err := psql.Select("p.paused").
From("pipelines p").
Where(sq.Eq{"p.id": p.id}).
err := psql.Select("paused").
From("pipelines").
Where(sq.Eq{"id": p.id}).
RunWith(p.conn).
QueryRow().
Scan(&paused)
@ -680,22 +681,6 @@ func (p *pipeline) Unpause() error {
return tx.Commit()
}
func (p *pipeline) PausedAt() time.Time {
if p.pausedAt.Valid {
return p.pausedAt.Time
} else {
return time.Time{}
}
}
func (p *pipeline) PausedBy() string {
if p.pausedBy.Valid {
return p.pausedBy.String
} else {
return ""
}
}
func (p *pipeline) Archive() error {
tx, err := p.conn.Begin()
if err != nil {

View File

@ -1426,8 +1426,10 @@ func scanPipeline(p *pipeline, scan scannable) error {
parentJobID sql.NullInt64
parentBuildID sql.NullInt64
instanceVars sql.NullString
pausedBy sql.NullString
pausedAt sql.NullTime
)
err := scan.Scan(&p.id, &p.name, &groups, &varSources, &display, &nonce, &p.configVersion, &p.teamID, &p.teamName, &p.paused, &p.public, &p.archived, &lastUpdated, &parentJobID, &parentBuildID, &instanceVars, &p.pausedBy, &p.pausedAt)
err := scan.Scan(&p.id, &p.name, &groups, &varSources, &display, &nonce, &p.configVersion, &p.teamID, &p.teamName, &p.paused, &p.public, &p.archived, &lastUpdated, &parentJobID, &parentBuildID, &instanceVars, &pausedBy, &pausedAt)
if err != nil {
return err
}
@ -1481,6 +1483,14 @@ func scanPipeline(p *pipeline, scan scannable) error {
}
}
if pausedBy.Valid {
p.pausedBy = pausedBy.String
}
if pausedAt.Valid {
p.pausedAt = pausedAt.Time
}
return nil
}

View File

@ -108,7 +108,7 @@ func (command *PausedPipelinesCommand) filter(pipelines []atc.Pipeline) []atc.Pi
pausedPipelines := make([]atc.Pipeline, 0)
for _, p := range pipelines {
if p.Paused {
pipelines = append(pipelines, p)
pausedPipelines = append(pausedPipelines, p)
}
}
return pausedPipelines