Skip to content

Commit

Permalink
fix(server): fix billing task concurrency overflow (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Jun 5, 2023
1 parent f49f44e commit b8cdc75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deploy/build/charts/laf-server/templates/metering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ spec:
env:
- name: MONGO_URI
value: {{ .Values.meteringDatabaseUrl | quote }}
image: docker.io/bxy4543/laf-resources-controller:v0.0.1
image: docker.io/bxy4543/laf-resources-controller:v0.0.2
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down
16 changes: 8 additions & 8 deletions server/src/billing/billing-task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class BillingTaskService {

constructor(private readonly billing: BillingService) {}

@Cron(CronExpression.EVERY_5_MINUTES)
@Cron(CronExpression.EVERY_10_MINUTES)
async createBillingScheduler() {
const db = SystemDatabase.db
if (ServerConfig.DISABLED_BILLING_TASK) {
Expand All @@ -42,11 +42,11 @@ export class BillingTaskService {
},
})

const concurrency = total > 30 ? 30 : total
if (total > 30) {
const concurrency = total > 10 ? 10 : total
if (total > 10) {
setTimeout(() => {
this.createBillingScheduler()
}, 3000)
}, 2000)
}

times(concurrency, () => {
Expand All @@ -56,7 +56,7 @@ export class BillingTaskService {
})
}

@Cron(CronExpression.EVERY_SECOND)
@Cron(CronExpression.EVERY_10_MINUTES)
async payBillingScheduler() {
const db = SystemDatabase.db
if (ServerConfig.DISABLED_BILLING_TASK) {
Expand All @@ -70,11 +70,11 @@ export class BillingTaskService {
lockedAt: { $lt: new Date(Date.now() - 1000 * 60) },
})

const concurrency = total > 30 ? 30 : total
if (total > 30) {
const concurrency = total > 10 ? 10 : total
if (total > 10) {
setTimeout(() => {
this.payBillingScheduler()
}, 3000)
}, 2000)
}

times(concurrency, () => {
Expand Down

0 comments on commit b8cdc75

Please sign in to comment.