Skip to content

Commit

Permalink
[preprocessor/folder] log error when setting db error status from caller
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 5, 2024
1 parent e76e219 commit 645450a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 2 additions & 5 deletions preprocessor/folder/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package folder

import (
"fmt"
"log"
"time"

"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -99,7 +98,7 @@ func setFileStatusDone(connPool *pgxpool.Pool, filePath string, cid string) erro
}

// setFileStatusError sets the status of a file to error with the error message
func setFileStatusError(connPool *pgxpool.Pool, filePath string, errorMessage string) {
func setFileStatusError(connPool *pgxpool.Pool, filePath string, errorMessage string) error {
_, err := connPool.Exec(
db.GetDatabaseContext(),
"UPDATE file_status SET status = $1, error = $2, updated_at = $3 WHERE file_path = $4;",
Expand All @@ -108,7 +107,5 @@ func setFileStatusError(connPool *pgxpool.Pool, filePath string, errorMessage st
time.Now().UTC(),
filePath,
)
if err != nil {
log.Println("error setting file status to error:", err)
}
return err
}
9 changes: 7 additions & 2 deletions preprocessor/folder/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package folder

import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -79,7 +80,9 @@ func handleNewFile(pgPool *pgxpool.Pool, filePath string) (string, error) {
}
metadata, err := getFileMetadata(filePath)
if err != nil {
setFileStatusError(pgPool, filePath, err.Error())
if err = setFileStatusError(pgPool, filePath, err.Error()); err != nil {
log.Println("error setting file status to error:", err)
}
return "", fmt.Errorf("error getting metadata for file %s: %v", filePath, err)
}
err = setFileStatusUploading(pgPool, filePath)
Expand All @@ -88,7 +91,9 @@ func handleNewFile(pgPool *pgxpool.Pool, filePath string) (string, error) {
}
resp, err := webhook.PostFileToWebHook(filePath, metadata, webhook.PostGenericWebhookOpt{})
if err != nil {
setFileStatusError(pgPool, filePath, err.Error())
if err = setFileStatusError(pgPool, filePath, err.Error()); err != nil {
log.Println("error setting file status to error:", err)
}
return "", fmt.Errorf("error posting metadata for file %s: %v", filePath, err)
}
err = setFileStatusDone(pgPool, filePath, cid)
Expand Down

0 comments on commit 645450a

Please sign in to comment.