feat: propagate job error codes (#6507)

* feat: propagate job error_code

* fix

* Fix

* Fix

* Fix

* add errors to typesGenerated

* Address PR comments

* Fix
This commit is contained in:
Marcin Tojek
2023-03-08 16:32:00 +01:00
committed by GitHub
parent 524b14adbc
commit 3b87316ad7
25 changed files with 406 additions and 234 deletions
+22
View File
@@ -6825,6 +6825,17 @@ const docTemplate = `{
}
}
},
"codersdk.JobErrorCode": {
"type": "string",
"enum": [
"MISSING_TEMPLATE_PARAMETER",
"REQUIRED_TEMPLATE_VARIABLES"
],
"x-enum-varnames": [
"MissingTemplateParameter",
"RequiredTemplateVariables"
]
},
"codersdk.License": {
"type": "object",
"properties": {
@@ -7362,6 +7373,17 @@ const docTemplate = `{
"error": {
"type": "string"
},
"error_code": {
"enum": [
"MISSING_TEMPLATE_PARAMETER",
"REQUIRED_TEMPLATE_VARIABLES"
],
"allOf": [
{
"$ref": "#/definitions/codersdk.JobErrorCode"
}
]
},
"file_id": {
"type": "string",
"format": "uuid"
+16
View File
@@ -6114,6 +6114,14 @@
}
}
},
"codersdk.JobErrorCode": {
"type": "string",
"enum": ["MISSING_TEMPLATE_PARAMETER", "REQUIRED_TEMPLATE_VARIABLES"],
"x-enum-varnames": [
"MissingTemplateParameter",
"RequiredTemplateVariables"
]
},
"codersdk.License": {
"type": "object",
"properties": {
@@ -6595,6 +6603,14 @@
"error": {
"type": "string"
},
"error_code": {
"enum": ["MISSING_TEMPLATE_PARAMETER", "REQUIRED_TEMPLATE_VARIABLES"],
"allOf": [
{
"$ref": "#/definitions/codersdk.JobErrorCode"
}
]
},
"file_id": {
"type": "string",
"format": "uuid"
+1
View File
@@ -3512,6 +3512,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCompleteByID(_ context.Context, ar
job.UpdatedAt = arg.UpdatedAt
job.CompletedAt = arg.CompletedAt
job.Error = arg.Error
job.ErrorCode = arg.ErrorCode
q.provisionerJobs[index] = job
return nil
}
+2 -1
View File
@@ -315,7 +315,8 @@ CREATE TABLE provisioner_jobs (
input jsonb NOT NULL,
worker_id uuid,
file_id uuid NOT NULL,
tags jsonb DEFAULT '{"scope": "organization"}'::jsonb NOT NULL
tags jsonb DEFAULT '{"scope": "organization"}'::jsonb NOT NULL,
error_code text
);
CREATE TABLE replicas (
@@ -0,0 +1 @@
ALTER TABLE provisioner_jobs DROP COLUMN error_code;
@@ -0,0 +1 @@
ALTER TABLE provisioner_jobs ADD COLUMN error_code text DEFAULT NULL;
+1
View File
@@ -1373,6 +1373,7 @@ type ProvisionerJob struct {
WorkerID uuid.NullUUID `db:"worker_id" json:"worker_id"`
FileID uuid.UUID `db:"file_id" json:"file_id"`
Tags dbtype.StringMap `db:"tags" json:"tags"`
ErrorCode sql.NullString `db:"error_code" json:"error_code"`
}
type ProvisionerJobLog struct {
+14 -6
View File
@@ -2426,7 +2426,7 @@ WHERE
SKIP LOCKED
LIMIT
1
) RETURNING id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags
) RETURNING id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags, error_code
`
type AcquireProvisionerJobParams struct {
@@ -2467,13 +2467,14 @@ func (q *sqlQuerier) AcquireProvisionerJob(ctx context.Context, arg AcquireProvi
&i.WorkerID,
&i.FileID,
&i.Tags,
&i.ErrorCode,
)
return i, err
}
const getProvisionerJobByID = `-- name: GetProvisionerJobByID :one
SELECT
id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags
id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags, error_code
FROM
provisioner_jobs
WHERE
@@ -2500,13 +2501,14 @@ func (q *sqlQuerier) GetProvisionerJobByID(ctx context.Context, id uuid.UUID) (P
&i.WorkerID,
&i.FileID,
&i.Tags,
&i.ErrorCode,
)
return i, err
}
const getProvisionerJobsByIDs = `-- name: GetProvisionerJobsByIDs :many
SELECT
id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags
id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags, error_code
FROM
provisioner_jobs
WHERE
@@ -2539,6 +2541,7 @@ func (q *sqlQuerier) GetProvisionerJobsByIDs(ctx context.Context, ids []uuid.UUI
&i.WorkerID,
&i.FileID,
&i.Tags,
&i.ErrorCode,
); err != nil {
return nil, err
}
@@ -2554,7 +2557,7 @@ func (q *sqlQuerier) GetProvisionerJobsByIDs(ctx context.Context, ids []uuid.UUI
}
const getProvisionerJobsCreatedAfter = `-- name: GetProvisionerJobsCreatedAfter :many
SELECT id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags FROM provisioner_jobs WHERE created_at > $1
SELECT id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags, error_code FROM provisioner_jobs WHERE created_at > $1
`
func (q *sqlQuerier) GetProvisionerJobsCreatedAfter(ctx context.Context, createdAt time.Time) ([]ProvisionerJob, error) {
@@ -2583,6 +2586,7 @@ func (q *sqlQuerier) GetProvisionerJobsCreatedAfter(ctx context.Context, created
&i.WorkerID,
&i.FileID,
&i.Tags,
&i.ErrorCode,
); err != nil {
return nil, err
}
@@ -2613,7 +2617,7 @@ INSERT INTO
tags
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING id, created_at, updated_at, started_at, canceled_at, completed_at, error, organization_id, initiator_id, provisioner, storage_method, type, input, worker_id, file_id, tags, error_code
`
type InsertProvisionerJobParams struct {
@@ -2662,6 +2666,7 @@ func (q *sqlQuerier) InsertProvisionerJob(ctx context.Context, arg InsertProvisi
&i.WorkerID,
&i.FileID,
&i.Tags,
&i.ErrorCode,
)
return i, err
}
@@ -2712,7 +2717,8 @@ UPDATE
SET
updated_at = $2,
completed_at = $3,
error = $4
error = $4,
error_code = $5
WHERE
id = $1
`
@@ -2722,6 +2728,7 @@ type UpdateProvisionerJobWithCompleteByIDParams struct {
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
CompletedAt sql.NullTime `db:"completed_at" json:"completed_at"`
Error sql.NullString `db:"error" json:"error"`
ErrorCode sql.NullString `db:"error_code" json:"error_code"`
}
func (q *sqlQuerier) UpdateProvisionerJobWithCompleteByID(ctx context.Context, arg UpdateProvisionerJobWithCompleteByIDParams) error {
@@ -2730,6 +2737,7 @@ func (q *sqlQuerier) UpdateProvisionerJobWithCompleteByID(ctx context.Context, a
arg.UpdatedAt,
arg.CompletedAt,
arg.Error,
arg.ErrorCode,
)
return err
}
+2 -1
View File
@@ -91,6 +91,7 @@ UPDATE
SET
updated_at = $2,
completed_at = $3,
error = $4
error = $4,
error_code = $5
WHERE
id = $1;
@@ -113,6 +113,7 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
String: errorMessage,
Valid: true,
},
ErrorCode: job.ErrorCode,
})
if err != nil {
return xerrors.Errorf("update provisioner job: %w", err)
@@ -639,12 +640,17 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
String: failJob.Error,
Valid: failJob.Error != "",
}
job.ErrorCode = sql.NullString{
String: failJob.ErrorCode,
Valid: failJob.ErrorCode != "",
}
err = server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
ID: jobID,
CompletedAt: job.CompletedAt,
UpdatedAt: database.Now(),
Error: job.Error,
ErrorCode: job.ErrorCode,
})
if err != nil {
return nil, xerrors.Errorf("update provisioner job: %w", err)
+1
View File
@@ -317,6 +317,7 @@ func convertProvisionerJob(provisionerJob database.ProvisionerJob) codersdk.Prov
ID: provisionerJob.ID,
CreatedAt: provisionerJob.CreatedAt,
Error: provisionerJob.Error.String,
ErrorCode: codersdk.JobErrorCode(provisionerJob.ErrorCode.String),
FileID: provisionerJob.FileID,
Tags: provisionerJob.Tags,
}