mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor(coderd/database): split Time and Now into dbtime package (#9482)
Ref: #9380
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbauthz"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/retry"
|
||||
)
|
||||
@@ -239,7 +240,7 @@ func (c *Cache) refreshTemplateDAUs(ctx context.Context) error {
|
||||
Valid: true,
|
||||
},
|
||||
StartTime: sql.NullTime{
|
||||
Time: database.Time(time.Now().AddDate(0, -30, 0)),
|
||||
Time: dbtime.Time(time.Now().AddDate(0, -30, 0)),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
@@ -256,7 +257,7 @@ func (c *Cache) refreshTemplateDAUs(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (c *Cache) refreshDeploymentStats(ctx context.Context) error {
|
||||
from := database.Now().Add(-15 * time.Minute)
|
||||
from := dbtime.Now().Add(-15 * time.Minute)
|
||||
agentStats, err := c.database.GetDeploymentWorkspaceAgentStats(ctx, from)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -267,8 +268,8 @@ func (c *Cache) refreshDeploymentStats(ctx context.Context) error {
|
||||
}
|
||||
c.deploymentStatsResponse.Store(&codersdk.DeploymentStats{
|
||||
AggregatedFrom: from,
|
||||
CollectedAt: database.Now(),
|
||||
NextUpdateAt: database.Now().Add(c.intervals.DeploymentStats),
|
||||
CollectedAt: dbtime.Now(),
|
||||
NextUpdateAt: dbtime.Now().Add(c.intervals.DeploymentStats),
|
||||
Workspaces: codersdk.WorkspaceDeploymentStats{
|
||||
Pending: workspaceStats.PendingWorkspaces,
|
||||
Building: workspaceStats.BuildingWorkspaces,
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbfake"
|
||||
"github.com/coder/coder/v2/coderd/database/dbgen"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/metricscache"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
@@ -444,7 +445,7 @@ func TestCache_DeploymentStats(t *testing.T) {
|
||||
_, err := db.InsertWorkspaceAgentStat(context.Background(), database.InsertWorkspaceAgentStatParams{
|
||||
ID: uuid.New(),
|
||||
AgentID: uuid.New(),
|
||||
CreatedAt: database.Now(),
|
||||
CreatedAt: dbtime.Now(),
|
||||
ConnectionCount: 1,
|
||||
RxBytes: 1,
|
||||
TxBytes: 1,
|
||||
|
||||
Reference in New Issue
Block a user