[messaging] add cronjob for workspaces messages partial sync (#3800)
* [messaging] add cronjob for workspaces messages partial sync * run cron every 10 minutes * use logger
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { FetchMessagesByBatchesService } from 'src/workspace/messaging/services/fetch-messages-by-batches.service';
|
||||
import { GmailClientProvider } from 'src/workspace/messaging/providers/gmail/gmail-client.provider';
|
||||
@ -16,6 +16,8 @@ import { WorkspaceDataSourceService } from 'src/workspace/workspace-datasource/w
|
||||
|
||||
@Injectable()
|
||||
export class GmailFullSyncService {
|
||||
private readonly logger = new Logger(GmailFullSyncService.name);
|
||||
|
||||
constructor(
|
||||
private readonly gmailClientProvider: GmailClientProvider,
|
||||
private readonly fetchMessagesByBatchesService: FetchMessagesByBatchesService,
|
||||
@ -135,7 +137,7 @@ export class GmailFullSyncService {
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
console.log(
|
||||
this.logger.log(
|
||||
`gmail full-sync for workspace ${workspaceId} and account ${connectedAccountId} ${
|
||||
nextPageToken ? `and ${nextPageToken} pageToken` : ''
|
||||
}done.`,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { gmail_v1 } from 'googleapis';
|
||||
|
||||
@ -17,6 +17,8 @@ import { WorkspaceDataSourceService } from 'src/workspace/workspace-datasource/w
|
||||
|
||||
@Injectable()
|
||||
export class GmailPartialSyncService {
|
||||
private readonly logger = new Logger(GmailPartialSyncService.name);
|
||||
|
||||
constructor(
|
||||
private readonly gmailClientProvider: GmailClientProvider,
|
||||
private readonly fetchMessagesByBatchesService: FetchMessagesByBatchesService,
|
||||
@ -77,6 +79,10 @@ export class GmailPartialSyncService {
|
||||
}
|
||||
|
||||
if (newHistoryId === lastSyncHistoryId) {
|
||||
this.logger.log(
|
||||
`gmail partial-sync for workspace ${workspaceId} and account ${connectedAccountId} done with nothing to update.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -127,6 +133,10 @@ export class GmailPartialSyncService {
|
||||
connectedAccount.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
this.logger.log(
|
||||
`gmail partial-sync for workspace ${workspaceId} and account ${connectedAccountId} done.`,
|
||||
);
|
||||
}
|
||||
|
||||
private async getMessageIdsFromHistory(
|
||||
|
||||
Reference in New Issue
Block a user