diff --git a/tools/certs/run.go b/tools/certs/run.go index 597e7d5..f0f05d7 100644 --- a/tools/certs/run.go +++ b/tools/certs/run.go @@ -3,18 +3,17 @@ package certsdb import ( "context" "fmt" - "log" "net/http" "time" ) -func run() { +func run() error { ctx := context.Background() // Choose DB implementation here (Mongo or SQLite) db, err := setupMongoCertDb() // db, err := setupSqliteCertDb("data/sqlite.db") if err != nil { - log.Fatalf("DB setup failed: %v", err) + return fmt.Errorf("DB setup failed: %w", err) } defer db.Disconnect(ctx) @@ -36,8 +35,9 @@ func run() { modified, err := db.CleanupInactive(ctx, now) if err != nil { - fmt.Println("Error updating inactive certificates:", err) + return fmt.Errorf("error updating inactive certificates: %w", err) } fmt.Println("Finished processing certificates at", nowStr) fmt.Printf("Updated %d certificates to inactive\n", modified) + return nil } diff --git a/tools/tpps/run.go b/tools/tpps/run.go index ccdfe7f..153595e 100644 --- a/tools/tpps/run.go +++ b/tools/tpps/run.go @@ -2,7 +2,6 @@ package tppsdb import ( "context" - "log" "github.com/botsman/tppVerifier/app/models" ) @@ -12,7 +11,7 @@ type Db interface { Disconnect(ctx context.Context) error } -func run() { +func run() error { // Download and parse the registry // populate DB // 1. Download metadata at https://euclid.eba.europa.eu/register/api/filemetadata?t=1737374419184 @@ -26,16 +25,13 @@ func run() { tppChan, err := parseRegistry() if err != nil { - log.Fatal(err) + return err } client, err := setupMongoDb() // client, err := setupSqliteDb("data/sqlite.db") if err != nil { - panic(err) + return err } defer client.Disconnect(context.TODO()) - err = saveTPPs(client, tppChan) - if err != nil { - log.Fatal(err) - } + return saveTPPs(client, tppChan) }