Skip to content

Commit

Permalink
chore(server): enhance billing loop when app stop -> start (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
0fatal authored Nov 9, 2023
1 parent 943ad92 commit 0f1b0e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion server/src/application/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class ApplicationService {
regionId: new ObjectId(dto.regionId),
runtimeId: new ObjectId(dto.runtimeId),
billingLockedAt: TASK_LOCK_INIT_TIME,
latestBillingTime: TASK_LOCK_INIT_TIME,
createdAt: new Date(),
updatedAt: new Date(),
},
Expand Down
2 changes: 1 addition & 1 deletion server/src/application/entities/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Application {

billingLockedAt: Date

latestBillingTime: Date
latestBillingTime?: Date

constructor(partial: Partial<Application>) {
Object.assign(this, partial)
Expand Down
10 changes: 10 additions & 0 deletions server/src/instance/instance-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class InstanceTaskService {
state: toState,
phase: ApplicationPhase.Started,
lockedAt: TASK_LOCK_INIT_TIME,
latestBillingTime: this.getHourTime(),
updatedAt: new Date(),
},
},
Expand Down Expand Up @@ -375,4 +376,13 @@ export class InstanceTaskService {
.collection<Application>('Application')
.updateOne({ appid: appid }, { $set: { lockedAt } })
}

private getHourTime() {
const latestTime = new Date()
latestTime.setMinutes(0)
latestTime.setSeconds(0)
latestTime.setMilliseconds(0)
latestTime.setHours(latestTime.getHours())
return latestTime
}
}

0 comments on commit 0f1b0e3

Please sign in to comment.