accounting/projectlimit: reset at the beginning of the month (#3796)
Co-authored-by: Stefan Benten <mail@stefan-benten.de>
This commit is contained in:
parent
ce1ae134a0
commit
02aee17cd9
@ -17,11 +17,6 @@ import (
|
||||
|
||||
var mon = monkit.Package()
|
||||
|
||||
const (
|
||||
// AverageDaysInMonth is how many days in a month
|
||||
AverageDaysInMonth = 30
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrProjectUsage general error for project usage
|
||||
ErrProjectUsage = errs.Class("project usage error")
|
||||
@ -123,7 +118,9 @@ func (usage *Service) GetProjectStorageTotals(ctx context.Context, projectID uui
|
||||
func (usage *Service) GetProjectBandwidthTotals(ctx context.Context, projectID uuid.UUID) (_ int64, err error) {
|
||||
defer mon.Task()(&ctx, projectID)(&err)
|
||||
|
||||
from := time.Now().AddDate(0, 0, -AverageDaysInMonth) // past 30 days
|
||||
// from the beginning of the current month
|
||||
year, month, _ := time.Now().Date()
|
||||
from := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
total, err := usage.projectAccountingDB.GetAllocatedBandwidthTotal(ctx, projectID, from)
|
||||
return total, ErrProjectUsage.Wrap(err)
|
||||
|
@ -215,7 +215,8 @@ func TestProjectBandwidthTotal(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Execute test: get project bandwidth total
|
||||
from := time.Now().AddDate(0, 0, -accounting.AverageDaysInMonth) // past 30 days
|
||||
year, month, _ := time.Now().Date()
|
||||
from := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
|
||||
actualBandwidthTotal, err := pdb.GetAllocatedBandwidthTotal(ctx, projectID, from)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, actualBandwidthTotal, expectedTotal)
|
||||
|
Loading…
Reference in New Issue
Block a user