Skip to content

Commit

Permalink
imager: update missed tui update for drivers and clean up task defini…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jsec committed Nov 24, 2024
1 parent 14b903d commit bbda29a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ tasks:

image:new:
cmds:
- cmd: rm -r data
silent: true
- task: image:up
- cmd: go run ./cmd/imager
silent: true
- task: db:push
- task: image:down
- cmd: rm -r data
silent: true
9 changes: 7 additions & 2 deletions internal/imager/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ type driver struct {
}

func (i imager) loadDrivers(ctx context.Context, tx pgx.Tx) error {
spinner := i.spinners.AddSpinner("Seeding drivers")

file, err := os.OpenFile("data/drivers.csv", os.O_RDONLY, 0600)
if err != nil {
spinner.Error()
return fmt.Errorf("error opening driver CSV file: %w", err)
}
defer file.Close()

var drivers []*driver

if err = gocsv.UnmarshalFile(file, &drivers); err != nil {
spinner.Error()
return fmt.Errorf("error marshaling driver CSV file: %w", err)
}

Expand All @@ -53,10 +57,11 @@ func (i imager) loadDrivers(ctx context.Context, tx pgx.Tx) error {
}

if err = i.driverService.SeedDrivers(ctx, tx, records); err != nil {
spinner.Error()
return fmt.Errorf("error saving drivers: %w", err)
}

fmt.Println("[Drivers] seeding complete")
spinner.Complete()
return nil
}

Expand All @@ -71,7 +76,7 @@ type driverStanding struct {
}

func (i imager) loadDriverStandings(ctx context.Context, tx pgx.Tx) error {
spinner := i.spinners.AddSpinner("Seeding drivers")
spinner := i.spinners.AddSpinner("Seeding driver standings")

file, err := os.OpenFile("data/driver_standings.csv", os.O_RDONLY, 0600)
if err != nil {
Expand Down

0 comments on commit bbda29a

Please sign in to comment.