worker/server: typesafe Job and JobStatus
Replace Job() and JobStatus() with typesafe versions, and introduce JobType() for the rare instances where we don't know the type up front. Additionally, catch a few more error cases: - if OSBuildResult is nil, then we failed to invoke osbuild - make sure the same JobResult handling is done for osbuild-koji, as for osbuild
This commit is contained in:
parent
da1537dee6
commit
b32ab36e1d
10 changed files with 240 additions and 202 deletions
|
|
@ -67,7 +67,7 @@ const (
|
|||
FROM jobs
|
||||
WHERE id = $1`
|
||||
sqlQueryJobStatus = `
|
||||
SELECT result, queued_at, started_at, finished_at, canceled
|
||||
SELECT type, result, queued_at, started_at, finished_at, canceled
|
||||
FROM jobs
|
||||
WHERE id = $1`
|
||||
sqlQueryRunningId = `
|
||||
|
|
@ -396,7 +396,7 @@ func (q *DBJobQueue) CancelJob(id uuid.UUID) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (q *DBJobQueue) JobStatus(id uuid.UUID) (result json.RawMessage, queued, started, finished time.Time, canceled bool, deps []uuid.UUID, err error) {
|
||||
func (q *DBJobQueue) JobStatus(id uuid.UUID) (jobType string, result json.RawMessage, queued, started, finished time.Time, canceled bool, deps []uuid.UUID, err error) {
|
||||
conn, err := q.pool.Acquire(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -406,7 +406,7 @@ func (q *DBJobQueue) JobStatus(id uuid.UUID) (result json.RawMessage, queued, st
|
|||
// Use double pointers for timestamps because they might be NULL, which would result in *time.Time == nil
|
||||
var sp, fp *time.Time
|
||||
var rp pgtype.JSON
|
||||
err = conn.QueryRow(context.Background(), sqlQueryJobStatus, id).Scan(&rp, &queued, &sp, &fp, &canceled)
|
||||
err = conn.QueryRow(context.Background(), sqlQueryJobStatus, id).Scan(&jobType, &rp, &queued, &sp, &fp, &canceled)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue