WIP: convert GORM to sqlc, for jobs/tasks #104304
@ -471,6 +471,23 @@ func (db *DB) FetchTask(ctx context.Context, taskUUID string) (*Task, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: remove this code, and let the caller fetch the job explicitly when needed.
|
||||
if taskRow.Task.JobID > 0 {
|
||||
dbJob, err := queries.FetchJobByID(ctx, taskRow.Task.JobID)
|
||||
if err != nil {
|
||||
return nil, jobError(err, "fetching job of task %s", taskUUID)
|
||||
}
|
||||
|
||||
convertedJob, err := convertSqlcJob(dbJob)
|
||||
if err != nil {
|
||||
return nil, jobError(err, "converting job of task %s", taskUUID)
|
||||
}
|
||||
convertedTask.Job = convertedJob
|
||||
if convertedTask.JobUUID != convertedJob.UUID {
|
||||
panic("Conversion to SQLC is incomplete")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove this code, and let the caller fetch the Worker explicitly when needed.
|
||||
if taskRow.WorkerUUID.Valid {
|
||||
worker, err := queries.FetchWorkerUnconditional(ctx, taskRow.WorkerUUID.String)
|
||||
|
@ -18,9 +18,15 @@ INSERT INTO jobs (
|
||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );
|
||||
|
||||
-- name: FetchJob :one
|
||||
-- Fetch a job by its UUID.
|
||||
SELECT * FROM jobs
|
||||
WHERE uuid = ? LIMIT 1;
|
||||
|
||||
-- name: FetchJobByID :one
|
||||
-- Fetch a job by its numerical ID.
|
||||
SELECT * FROM jobs
|
||||
WHERE id = ? LIMIT 1;
|
||||
|
||||
-- name: DeleteJob :exec
|
||||
DELETE FROM jobs WHERE uuid = ?;
|
||||
|
||||
|
@ -74,6 +74,7 @@ SELECT id, created_at, updated_at, uuid, name, job_type, priority, status, activ
|
||||
WHERE uuid = ? LIMIT 1
|
||||
`
|
||||
|
||||
// Fetch a job by its UUID.
|
||||
func (q *Queries) FetchJob(ctx context.Context, uuid string) (Job, error) {
|
||||
row := q.db.QueryRowContext(ctx, fetchJob, uuid)
|
||||
var i Job
|
||||
@ -96,6 +97,34 @@ func (q *Queries) FetchJob(ctx context.Context, uuid string) (Job, error) {
|
||||
return i, err
|
||||
}
|
||||
|
||||
const fetchJobByID = `-- name: FetchJobByID :one
|
||||
SELECT id, created_at, updated_at, uuid, name, job_type, priority, status, activity, settings, metadata, delete_requested_at, storage_shaman_checkout_id, worker_tag_id FROM jobs
|
||||
WHERE id = ? LIMIT 1
|
||||
`
|
||||
|
||||
// Fetch a job by its numerical ID.
|
||||
func (q *Queries) FetchJobByID(ctx context.Context, id int64) (Job, error) {
|
||||
row := q.db.QueryRowContext(ctx, fetchJobByID, id)
|
||||
var i Job
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.UUID,
|
||||
&i.Name,
|
||||
&i.JobType,
|
||||
&i.Priority,
|
||||
&i.Status,
|
||||
&i.Activity,
|
||||
&i.Settings,
|
||||
&i.Metadata,
|
||||
&i.DeleteRequestedAt,
|
||||
&i.StorageShamanCheckoutID,
|
||||
&i.WorkerTagID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const fetchJobUUIDsUpdatedBefore = `-- name: FetchJobUUIDsUpdatedBefore :many
|
||||
SELECT uuid FROM jobs WHERE updated_at <= ?1
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user