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

Function fetchAndWriteLogs

coderd/provisionerjobs.go:444–470  ·  view source on GitHub ↗
(ctx context.Context, db database.Store, jobID uuid.UUID, after int64, rw http.ResponseWriter, format string)

Source from the content-addressed store, hash-verified

442}
443
444func fetchAndWriteLogs(ctx context.Context, db database.Store, jobID uuid.UUID, after int64, rw http.ResponseWriter, format string) {
445 logs, err := db.GetProvisionerLogsAfterID(ctx, database.GetProvisionerLogsAfterIDParams{
446 JobID: jobID,
447 CreatedAfter: after,
448 })
449 if err != nil && !errors.Is(err, sql.ErrNoRows) {
450 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
451 Message: "Internal error fetching provisioner logs.",
452 Detail: err.Error(),
453 })
454 return
455 }
456 if logs == nil {
457 logs = []database.ProvisionerJobLog{}
458 }
459
460 if format == "text" {
461 rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
462 rw.WriteHeader(http.StatusOK)
463 for _, log := range logs {
464 _, _ = rw.Write([]byte(db2sdk.ProvisionerJobLog(log).Text()))
465 _, _ = rw.Write([]byte("\n"))
466 }
467 return
468 }
469 httpapi.Write(ctx, rw, http.StatusOK, convertProvisionerJobLogs(logs))
470}
471
472func jobIsComplete(logger slog.Logger, job database.ProvisionerJob) bool {
473 status := codersdk.ProvisionerJobStatus(job.JobStatus)

Callers 1

provisionerJobLogsMethod · 0.85

Calls 11

WriteFunction · 0.92
ProvisionerJobLogFunction · 0.92
SetMethod · 0.65
WriteMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
TextMethod · 0.45

Tested by

no test coverage detected