Skip to content

Commit

Permalink
Merge pull request #490 from getAlby/invoice-republishing-by-hash
Browse files Browse the repository at this point in the history
added single invoice by hash support for republishing
  • Loading branch information
bumi authored Jun 7, 2024
2 parents ba5057c + 47333eb commit 692efdc
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/invoice-republishing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ func main() {
fmt.Println("Failed to load .env file")
}
logger := lib.Logger(c.LogFilePath)
startDate, endDate, err := loadStartAndEndIdFromEnv()
if err != nil {
logger.Fatalf("Could not load start and end id from env %v", err)
}

err = envconfig.Process("", c)
if err != nil {
logger.Fatalf("Error loading environment variables: %v", err)
Expand Down Expand Up @@ -63,7 +60,20 @@ func main() {
defer rabbitmqClient.Close()

result := []models.Invoice{}
err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background())

singleInvoiceHash := os.Getenv("REPUBLISH_INVOICE_HASH")

if singleInvoiceHash != "" {
err = dbConn.NewSelect().Model(&result).Where("r_hash = ?", singleInvoiceHash).Scan(context.Background())
} else {
startDate, endDate, err1 := loadStartAndEndIdFromEnv()

if err1 != nil {
logger.Fatalf("Could not load start and end id from env %v", err1)
}

err = dbConn.NewSelect().Model(&result).Where("settled_at > ?", startDate).Where("settled_at < ?", endDate).Scan(context.Background())
}
if err != nil {
logger.Fatal(err)
}
Expand Down

0 comments on commit 692efdc

Please sign in to comment.