Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
Change how counts table is populated (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
fischersean committed Dec 11, 2021
1 parent 10ee524 commit 2e1b507
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions cmd/lambda/update-distdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,44 @@ func repopulateSymbols(conn *sql.DB, s3Service *s3.S3) (err error) {

func repopulateCounts(conn *sql.DB, sess *session.Session) (err error) {

// Empty table
err = clearTbl(conn, "Counts")
dynamoConn, err := db.Connect(db.ConnectionInput{
Session: sess,
})
if err != nil {
return err
}

dynamoConn, err := db.Connect(db.ConnectionInput{
Session: sess,
})
// get oldest date
stmtString := `
SELECT
FormatedDate
FROM Counts
ORDER BY FormatedDate DESC
LIMIT 1`
stmt, err := conn.Prepare(stmtString)
if err != nil {
return err
}

res, err := stmt.Query()
if err != nil {
return err
}

var strDate string // the formated date. will convert later
res.Next()
err = res.Scan(&strDate)
if err != nil {
return err
}
res.Close()

stopDate, err := time.Parse(time.RFC822, "20 Mar 21 00:00 UTC")
stopDate, err := time.Parse("20060102", strDate)
if err != nil {
return err
}

// Starting from today and working backwards, fill in all missing dates
for date := time.Now(); date.After(stopDate); date = date.Add(-24 * time.Hour) {
for _, sub := range etl.FetchTargets {
etlRecords, err := dynamoConn.GetEtlResultsRecord(db.EtlResultsQueryInput{
Expand Down

0 comments on commit 2e1b507

Please sign in to comment.