storj/pkg/accounting/rollup/rollup.go
Jennifer Li Johnson 377832c705
Create Tally and Rollup pkgs in accounting (#642)
* creates separate tally and rollup packages and writes skeleton for rollup

* TODO add rollupDB and rawDB to rollup struct

* TODO add rawDB to tally struct
2018-11-13 20:22:18 -05:00

57 lines
1015 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package rollup
import (
"context"
"time"
"go.uber.org/zap"
)
// Rollup is the service for totalling data on storage nodes for 1, 7, 30 day intervals
type Rollup interface {
Run(ctx context.Context) error
}
type rollup struct {
logger *zap.Logger
ticker *time.Ticker
//TODO:
//rollupDB
//rawDB
}
func newRollup(logger *zap.Logger, interval time.Duration) *rollup {
return &rollup{
logger: logger,
ticker: time.NewTicker(interval),
//TODO:
//rollupDB
//rawDB
}
}
// Run the rollup loop
func (r *rollup) Run(ctx context.Context) (err error) {
defer mon.Task()(&ctx)(&err)
for {
err = r.Query(ctx)
if err != nil {
zap.L().Error("Rollup Query failed", zap.Error(err))
}
select {
case <-r.ticker.C: // wait for the next interval to happen
case <-ctx.Done(): // or the rollup is canceled via context
return ctx.Err()
}
}
}
func (r *rollup) Query(ctx context.Context) error {
return nil
}