Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .plans/minimal-slog-logging/completed/01-tracer-logger.md

This file was deleted.

42 changes: 0 additions & 42 deletions .plans/minimal-slog-logging/completed/02-request-backbone.md

This file was deleted.

43 changes: 0 additions & 43 deletions .plans/minimal-slog-logging/completed/03-job-create-flow.md

This file was deleted.

42 changes: 0 additions & 42 deletions .plans/minimal-slog-logging/completed/04-async-job-lifecycle.md

This file was deleted.

42 changes: 0 additions & 42 deletions .plans/minimal-slog-logging/completed/05-cleanup-visibility.md

This file was deleted.

48 changes: 0 additions & 48 deletions .plans/minimal-slog-logging/plan.md

This file was deleted.

6 changes: 4 additions & 2 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package api

import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
"path/filepath"
"strings"
"time"

"github.com/go-chi/chi/v5"
Expand Down Expand Up @@ -104,8 +106,8 @@ func writeAcceptedJobResponse(w http.ResponseWriter, job jobs.Job) {
}

func writeCreateJobError(w http.ResponseWriter, logger *slog.Logger, requestedType string, err error) {
if service.IsCreateJobRequestError(err) {
http.Error(w, err.Error(), http.StatusBadRequest)
if errors.Is(err, service.ErrCreateJobRequest) {
http.Error(w, strings.TrimPrefix(err.Error(), service.ErrCreateJobRequest.Error()+": "), http.StatusBadRequest)
return
}

Expand Down
29 changes: 21 additions & 8 deletions internal/artifacts/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"archive/tar"
"archive/zip"
"compress/gzip"
"context"
"fmt"
"os"
"path/filepath"
)

func CreateZipFromRoot(dest, sourceRoot string, files []string, onProgress func(int)) error {
func CreateZipFromRoot(ctx context.Context, dest, sourceRoot string, files []string, onProgress func(int)) error {
total, err := totalFileSize(archiveSourcePaths(sourceRoot, files))
if err != nil {
return fmt.Errorf("calculate zip progress: %w", err)
Expand All @@ -21,20 +22,26 @@ func CreateZipFromRoot(dest, sourceRoot string, files []string, onProgress func(
return fmt.Errorf("create zip file: %w", err)
}
defer f.Close()
if err := checkContext(ctx); err != nil {
return err
}

zw := zip.NewWriter(f)
defer zw.Close()

for _, file := range files {
if err := addFileToZip(zw, archiveSourcePath(sourceRoot, file), file, reporter); err != nil {
if err := checkContext(ctx); err != nil {
return err
}
if err := addFileToZip(ctx, zw, archiveSourcePath(sourceRoot, file), file, reporter); err != nil {
return fmt.Errorf("add %s: %w", file, err)
}
}

return nil
}

func addFileToZip(zw *zip.Writer, sourcePath, archivePath string, reporter *progressReporter) error {
func addFileToZip(ctx context.Context, zw *zip.Writer, sourcePath, archivePath string, reporter *progressReporter) error {
src, err := os.Open(sourcePath)
if err != nil {
return err
Expand All @@ -58,10 +65,10 @@ func addFileToZip(zw *zip.Writer, sourcePath, archivePath string, reporter *prog
return err
}

return copyWithProgress(w, src, reporter)
return copyWithProgressContext(ctx, w, src, reporter)
}

func CreateTarballFromRoot(dest, sourceRoot string, files []string, onProgress func(int)) error {
func CreateTarballFromRoot(ctx context.Context, dest, sourceRoot string, files []string, onProgress func(int)) error {
total, err := totalFileSize(archiveSourcePaths(sourceRoot, files))
if err != nil {
return fmt.Errorf("calculate tarball progress: %w", err)
Expand All @@ -73,6 +80,9 @@ func CreateTarballFromRoot(dest, sourceRoot string, files []string, onProgress f
return fmt.Errorf("create tarball file: %w", err)
}
defer f.Close()
if err := checkContext(ctx); err != nil {
return err
}

gzw := gzip.NewWriter(f)
defer gzw.Close()
Expand All @@ -81,15 +91,18 @@ func CreateTarballFromRoot(dest, sourceRoot string, files []string, onProgress f
defer tw.Close()

for _, file := range files {
if err := addFileToTarball(tw, archiveSourcePath(sourceRoot, file), file, reporter); err != nil {
if err := checkContext(ctx); err != nil {
return err
}
if err := addFileToTarball(ctx, tw, archiveSourcePath(sourceRoot, file), file, reporter); err != nil {
return fmt.Errorf("add %s: %w", file, err)
}
}

return nil
}

func addFileToTarball(tw *tar.Writer, sourcePath, archivePath string, reporter *progressReporter) error {
func addFileToTarball(ctx context.Context, tw *tar.Writer, sourcePath, archivePath string, reporter *progressReporter) error {
src, err := os.Open(sourcePath)
if err != nil {
return err
Expand All @@ -111,7 +124,7 @@ func addFileToTarball(tw *tar.Writer, sourcePath, archivePath string, reporter *
return err
}

return copyWithProgress(tw, src, reporter)
return copyWithProgressContext(ctx, tw, src, reporter)
}

func archiveSourcePaths(sourceRoot string, files []string) []string {
Expand Down
Loading