Actually start reading CSV file

This commit is contained in:
Eli Ribble 2026-02-08 04:46:54 +00:00
parent 6b02b75a87
commit e81161ca7f
No known key found for this signature in database
3 changed files with 30 additions and 7 deletions

View file

@ -26,7 +26,7 @@ func startWorkerCSV(ctx context.Context, channelJobImport chan jobImportCSVPool)
return
case job := <-channelJobImport:
log.Info().Int32("id", job.fileID).Msg("Processing CSV job")
err := csv.ProcessJob(job.fileID)
err := csv.ProcessJob(ctx, job.fileID)
if err != nil {
log.Error().Err(err).Int32("id", job.fileID).Msg("Error processing CSV file")
}

View file

@ -1,13 +1,31 @@
package csv
import (
//"encoding/csv"
//"github.com/Gleipnir-Technology/nidus-sync/platform/csv"
//"github.com/Gleipnir-Technology/nidus-sync/userfile"
//"github.com/rs/zerolog/log"
"context"
"encoding/csv"
"fmt"
"github.com/Gleipnir-Technology/nidus-sync/db"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/Gleipnir-Technology/nidus-sync/userfile"
"github.com/rs/zerolog/log"
)
func ProcessJob(file_id int32) error {
//userfile.NewFileReader("csv"
func ProcessJob(ctx context.Context, file_id int32) error {
file, err := models.FindFileuploadFile(ctx, db.PGInstance.BobDB, file_id)
if err != nil {
return fmt.Errorf("Failed to get file %d from DB: %w", file_id, err)
}
r, err := userfile.NewFileReader(userfile.CollectionCSV, file.FileUUID)
if err != nil {
return fmt.Errorf("Failed to get filereader for %d: %w", file_id, err)
}
reader := csv.NewReader(r)
records, err := reader.ReadAll()
if err != nil {
return fmt.Errorf("Failed to read all CSV records for file %d: %w", file_id, err)
}
for _, rec := range records {
log.Debug().Strs("rec", rec).Msg("Line")
}
return nil
}

View file

@ -29,3 +29,8 @@ func FileContentWrite(body io.Reader, collection Collection, uid uuid.UUID) erro
log.Info().Str("filepath", filepath).Msg("Save audio file content")
return nil
}
func NewFileReader(collection Collection, uid uuid.UUID) (io.Reader, error) {
path := fileContentPath(collection, uid)
return os.Open(path)
}