refactor: unify logging messages in CronService for consistency
- Updated log messages in the CronService to use a consistent logger context ('CronService') across all scheduled tasks.
- Improved traceability and readability of log outputs by standardizing the log context, enhancing debugging capabilities.
This commit is contained in:
@@ -16,7 +16,7 @@ export class CronService {
|
||||
// cron every 1 minute to check schedule date status
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async checkScheduleDateStatus() {
|
||||
Logger.log('Checking schedule date status', 'checkScheduleDateStatus')
|
||||
Logger.log('Checking schedule date status', 'CronService')
|
||||
const schedules = await this.prisma.scheduleDate.findMany({
|
||||
where: {
|
||||
end: {
|
||||
@@ -27,7 +27,7 @@ export class CronService {
|
||||
},
|
||||
},
|
||||
})
|
||||
Logger.log(`Found ${schedules.length} schedules to update`, 'checkScheduleDateStatus')
|
||||
Logger.log(`Found ${schedules.length} schedules to update`, 'CronService')
|
||||
// get all collaboration sessions
|
||||
const collaborationSessions = await this.prisma.collaborationSession.findMany({
|
||||
where: {
|
||||
@@ -77,7 +77,7 @@ export class CronService {
|
||||
// cron every 1 minute to check payment status where created_at is more than 15 minutes
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async checkPaymentStatus() {
|
||||
Logger.log('Checking payment status', 'checkPaymentStatus')
|
||||
Logger.log('Checking payment status', 'CronService')
|
||||
const payments = await this.prisma.payment.findMany({
|
||||
where: {
|
||||
status: PaymentStatus.PENDING,
|
||||
@@ -86,7 +86,7 @@ export class CronService {
|
||||
},
|
||||
},
|
||||
})
|
||||
Logger.log(`Found ${payments.length} payments to update`, 'checkPaymentStatus')
|
||||
Logger.log(`Found ${payments.length} payments to update`, 'CronService')
|
||||
for (const payment of payments) {
|
||||
await this.prisma.payment.update({
|
||||
where: { id: payment.id },
|
||||
@@ -102,7 +102,7 @@ export class CronService {
|
||||
// handle refund ticket by order, if order status is refunded, disable schedule and remove schedule date in future
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async taskRefundTicket() {
|
||||
Logger.log('Handling refund ticket', 'handleRefundTicket')
|
||||
Logger.log('Handling refund ticket', 'CronService')
|
||||
const now = DateTimeUtils.now().toJSDate()
|
||||
// get all orders where status is REFUNDED and has schedule.dates in future
|
||||
const orders = await this.prisma.order.findMany({
|
||||
@@ -126,7 +126,7 @@ export class CronService {
|
||||
},
|
||||
},
|
||||
})
|
||||
Logger.log(`Found ${orders.length} orders to handle`, 'handleRefundTicket')
|
||||
Logger.log(`Found ${orders.length} orders to handle`, 'CronService')
|
||||
for (const order of orders) {
|
||||
await this.prisma.schedule.update({
|
||||
where: { id: order.scheduleId },
|
||||
@@ -147,7 +147,7 @@ export class CronService {
|
||||
// cron every 1 minute to check if there is any schedule date start in less than 30 minutes
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async taskCheckScheduleDateStart() {
|
||||
Logger.log('Checking schedule date start', 'taskCheckScheduleDateStart')
|
||||
Logger.log('Checking schedule date start', 'CronService')
|
||||
const schedules = await this.prisma.schedule.findMany({
|
||||
where: {
|
||||
AND: [
|
||||
@@ -162,7 +162,7 @@ export class CronService {
|
||||
],
|
||||
},
|
||||
})
|
||||
Logger.log(`Found ${schedules.length} schedules to check`, 'taskCheckScheduleDateStart')
|
||||
Logger.log(`Found ${schedules.length} schedules to check`, 'CronService')
|
||||
for (const schedule of schedules) {
|
||||
await this.prisma.scheduleDate.updateMany({
|
||||
where: { scheduleId: schedule.id },
|
||||
@@ -192,7 +192,7 @@ export class CronService {
|
||||
// cron every day to disable service without any schedule in the past 30 days
|
||||
@Cron(CronExpression.EVERY_DAY_AT_1AM)
|
||||
async taskDisableServiceWithoutSchedule() {
|
||||
Logger.log('Disabling service without any schedule', 'taskDisableServiceWithoutSchedule')
|
||||
Logger.log('Disabling service without any schedule', 'CronService')
|
||||
const services = await this.prisma.managedService.findMany({
|
||||
where: {
|
||||
NOT: {
|
||||
@@ -216,7 +216,7 @@ export class CronService {
|
||||
},
|
||||
},
|
||||
})
|
||||
Logger.log(`Service ${service.id} has been disabled`, 'taskDisableServiceWithoutSchedule')
|
||||
Logger.log(`Service ${service.id} has been disabled`, 'CronService')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user