MCPcopy Index your code
hub / github.com/coder/coder / ProvisionerJob

Function ProvisionerJob

coderd/database/dbgen/dbgen.go:1192–1269  ·  view source on GitHub ↗

ProvisionerJob is a bit more involved to get the values such as "completedAt", "startedAt", "cancelledAt" set. ps can be set to nil if you are SURE that you don't require a provisionerdaemon to acquire the job in your test.

(t testing.TB, db database.Store, ps pubsub.Pubsub, orig database.ProvisionerJob)

Source from the content-addressed store, hash-verified

1190// ProvisionerJob is a bit more involved to get the values such as "completedAt", "startedAt", "cancelledAt" set. ps
1191// can be set to nil if you are SURE that you don't require a provisionerdaemon to acquire the job in your test.
1192func ProvisionerJob(t testing.TB, db database.Store, ps pubsub.Pubsub, orig database.ProvisionerJob) database.ProvisionerJob {
1193 t.Helper()
1194
1195 var defOrgID uuid.UUID
1196 if orig.OrganizationID == uuid.Nil {
1197 defOrg, _ := db.GetDefaultOrganization(genCtx)
1198 defOrgID = defOrg.ID
1199 }
1200
1201 jobID := takeFirst(orig.ID, uuid.New())
1202
1203 // Always set some tags to prevent Acquire from grabbing jobs it should not.
1204 tags := maps.Clone(orig.Tags)
1205 if !orig.StartedAt.Time.IsZero() {
1206 if tags == nil {
1207 tags = make(database.StringMap)
1208 }
1209 // Make sure when we acquire the job, we only get this one.
1210 tags[jobID.String()] = "true"
1211 }
1212
1213 job, err := db.InsertProvisionerJob(genCtx, database.InsertProvisionerJobParams{
1214 ID: jobID,
1215 CreatedAt: takeFirst(orig.CreatedAt, dbtime.Now()),
1216 UpdatedAt: takeFirst(orig.UpdatedAt, dbtime.Now()),
1217 OrganizationID: takeFirst(orig.OrganizationID, defOrgID, uuid.New()),
1218 InitiatorID: takeFirst(orig.InitiatorID, uuid.New()),
1219 Provisioner: takeFirst(orig.Provisioner, database.ProvisionerTypeEcho),
1220 StorageMethod: takeFirst(orig.StorageMethod, database.ProvisionerStorageMethodFile),
1221 FileID: takeFirst(orig.FileID, uuid.New()),
1222 Type: takeFirst(orig.Type, database.ProvisionerJobTypeWorkspaceBuild),
1223 Input: takeFirstSlice(orig.Input, []byte("{}")),
1224 Tags: tags,
1225 TraceMetadata: pqtype.NullRawMessage{},
1226 LogsOverflowed: false,
1227 })
1228 require.NoError(t, err, "insert job")
1229 if ps != nil {
1230 err = provisionerjobs.PostJob(ps, job)
1231 require.NoError(t, err, "post job to pubsub")
1232 }
1233 if !orig.StartedAt.Time.IsZero() {
1234 job, err = db.AcquireProvisionerJob(genCtx, database.AcquireProvisionerJobParams{
1235 StartedAt: orig.StartedAt,
1236 OrganizationID: job.OrganizationID,
1237 Types: []database.ProvisionerType{job.Provisioner},
1238 ProvisionerTags: must(json.Marshal(tags)),
1239 WorkerID: takeFirst(orig.WorkerID, uuid.NullUUID{}),
1240 })
1241 require.NoError(t, err)
1242 // There is no easy way to make sure we acquire the correct job.
1243 require.Equal(t, jobID, job.ID, "acquired incorrect job")
1244 }
1245
1246 if !orig.CompletedAt.Time.IsZero() || orig.Error.String != "" {
1247 err = db.UpdateProvisionerJobWithCompleteByID(genCtx, database.UpdateProvisionerJobWithCompleteByIDParams{
1248 ID: jobID,
1249 UpdatedAt: job.UpdatedAt,

Calls 15

NowFunction · 0.92
PostJobFunction · 0.92
takeFirstSliceFunction · 0.85
takeFirstFunction · 0.70
mustFunction · 0.70
HelperMethod · 0.65
NewMethod · 0.65
InsertProvisionerJobMethod · 0.65
AcquireProvisionerJobMethod · 0.65