rollup timestamp fix (#1132)
* create timestamp if isNew * pass isNil into SaveRollup
This commit is contained in:
parent
187e9b2138
commit
f5b1e77cf2
@ -53,7 +53,7 @@ type DB interface {
|
||||
// GetRawSince r retrieves all raw tallies sinces
|
||||
GetRawSince(ctx context.Context, latestRollup time.Time) ([]*Raw, error)
|
||||
// SaveRollup records raw tallies of at rest data to the database
|
||||
SaveRollup(ctx context.Context, latestTally time.Time, stats RollupStats) error
|
||||
SaveRollup(ctx context.Context, latestTally time.Time, isNew bool, stats RollupStats) error
|
||||
// QueryPaymentInfo queries StatDB, Accounting Rollup on nodeID
|
||||
QueryPaymentInfo(ctx context.Context, start time.Time, end time.Time) ([]*CSVRow, error)
|
||||
}
|
||||
|
@ -115,5 +115,5 @@ func (r *Rollup) Query(ctx context.Context) error {
|
||||
r.logger.Info("Rollup only found tallies for today")
|
||||
return nil
|
||||
}
|
||||
return Error.Wrap(r.db.SaveRollup(ctx, latestTally, rollupStats))
|
||||
return Error.Wrap(r.db.SaveRollup(ctx, latestTally, isNil, rollupStats))
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func (db *accountingDB) GetRawSince(ctx context.Context, latestRollup time.Time)
|
||||
}
|
||||
|
||||
// SaveRollup records raw tallies of at rest data to the database
|
||||
func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time, stats accounting.RollupStats) error {
|
||||
func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time, isNew bool, stats accounting.RollupStats) error {
|
||||
if len(stats) == 0 {
|
||||
return Error.New("In SaveRollup with empty nodeData")
|
||||
}
|
||||
@ -183,8 +183,13 @@ func (db *accountingDB) SaveRollup(ctx context.Context, latestRollup time.Time,
|
||||
}
|
||||
}
|
||||
}
|
||||
update := dbx.AccountingTimestamps_Update_Fields{Value: dbx.AccountingTimestamps_Value(latestRollup)}
|
||||
_, err = tx.Update_AccountingTimestamps_By_Name(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update)
|
||||
if isNew {
|
||||
update := dbx.AccountingTimestamps_Value(latestRollup)
|
||||
_, err = tx.Create_AccountingTimestamps(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update)
|
||||
} else {
|
||||
update := dbx.AccountingTimestamps_Update_Fields{Value: dbx.AccountingTimestamps_Value(latestRollup)}
|
||||
_, err = tx.Update_AccountingTimestamps_By_Name(ctx, dbx.AccountingTimestamps_Name(accounting.LastRollup), update)
|
||||
}
|
||||
return Error.Wrap(err)
|
||||
}
|
||||
|
||||
|
@ -84,10 +84,10 @@ func (m *lockedAccounting) SaveBWRaw(ctx context.Context, latestBwa time.Time, i
|
||||
}
|
||||
|
||||
// SaveRollup records raw tallies of at rest data to the database
|
||||
func (m *lockedAccounting) SaveRollup(ctx context.Context, latestTally time.Time, stats accounting.RollupStats) error {
|
||||
func (m *lockedAccounting) SaveRollup(ctx context.Context, latestTally time.Time, isNew bool, stats accounting.RollupStats) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
return m.db.SaveRollup(ctx, latestTally, stats)
|
||||
return m.db.SaveRollup(ctx, latestTally, isNew, stats)
|
||||
}
|
||||
|
||||
// BandwidthAgreement returns database for storing bandwidth agreements
|
||||
|
Loading…
Reference in New Issue
Block a user