Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/republish invoices #350

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions republish_invoices/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"time"

"github.com/getAlby/lndhub.go/db"
"github.com/getAlby/lndhub.go/db/models"
Expand All @@ -24,7 +24,7 @@ func main() {
if err != nil {
fmt.Println("Failed to load .env file")
}
startId, endId, err := loadStartAndEndIdFromEnv()
startDate, endDate, err := loadStartAndEndIdFromEnv()
if err != nil {
log.Fatalf("Could not load start and end id from env %v", err)
}
Expand All @@ -50,7 +50,7 @@ func main() {
defer rabbitmqClient.Close()

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only publish settled invoices, correct? thus it's ok to check settled there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If settled_at is between those 2 values, then it's settled.

if err != nil {
log.Fatal(err)
}
Expand All @@ -75,14 +75,11 @@ func main() {

}

func loadStartAndEndIdFromEnv() (start, end int, err error) {
start, err = strconv.Atoi(os.Getenv("START_ID"))
func loadStartAndEndIdFromEnv() (start, end time.Time, err error) {
start, err = time.Parse(time.RFC3339, os.Getenv("START_DATE"))
if err != nil {
return 0, 0, err
return
}
end, err = strconv.Atoi(os.Getenv("END_ID"))
if err != nil {
return 0, 0, err
}
return start, end, nil
end, err = time.Parse(time.RFC3339, os.Getenv("END_DATE"))
return
}