mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-26 11:34:58 +02:00
Extra calendar logs (#9390)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
//
|
||||
|
||||
import { AccountClient } from '@hcengineering/account-client'
|
||||
import core, { isActiveMode, MeasureContext, TxOperations } from '@hcengineering/core'
|
||||
import { isActiveMode, MeasureContext, TxOperations } from '@hcengineering/core'
|
||||
import { getClient } from './client'
|
||||
import { getUserByEmail, removeUserByEmail } from './kvsUtils'
|
||||
import { IncomingSyncManager } from './sync'
|
||||
@@ -32,22 +32,31 @@ export class PushHandler {
|
||||
'Push handler',
|
||||
{},
|
||||
async () => {
|
||||
const client = await getClient(getWorkspaceToken(token.workspace))
|
||||
const txOp = new TxOperations(client, core.account.System)
|
||||
const res = getGoogleClient()
|
||||
const authSuccess = await setCredentials(res.auth, token)
|
||||
if (!authSuccess) {
|
||||
await removeUserByEmail(token, token.email)
|
||||
await removeIntegrationSecret(this.ctx, this.accountClient, {
|
||||
kind: CALENDAR_INTEGRATION,
|
||||
workspaceUuid: token.workspace,
|
||||
socialId: token.userId,
|
||||
key: token.email
|
||||
try {
|
||||
const client = await getClient(getWorkspaceToken(token.workspace))
|
||||
const res = getGoogleClient()
|
||||
const authSuccess = await setCredentials(res.auth, token)
|
||||
if (!authSuccess) {
|
||||
await removeUserByEmail(token, token.email)
|
||||
await removeIntegrationSecret(this.ctx, this.accountClient, {
|
||||
kind: CALENDAR_INTEGRATION,
|
||||
workspaceUuid: token.workspace,
|
||||
socialId: token.userId,
|
||||
key: token.email
|
||||
})
|
||||
} else {
|
||||
const txOp = new TxOperations(client, token.userId)
|
||||
await IncomingSyncManager.push(this.ctx, this.accountClient, txOp, token, res.google, calendarId)
|
||||
await txOp.close()
|
||||
}
|
||||
} catch (err) {
|
||||
this.ctx.error('Push sync error', {
|
||||
user: token.userId,
|
||||
workspace: token.workspace,
|
||||
email: token.email,
|
||||
error: err instanceof Error ? err.message : String(err)
|
||||
})
|
||||
} else {
|
||||
await IncomingSyncManager.push(this.ctx, this.accountClient, txOp, token, res.google, calendarId)
|
||||
}
|
||||
await txOp.close()
|
||||
},
|
||||
{ workspace: token.workspace, user: token.userId }
|
||||
)
|
||||
@@ -55,6 +64,7 @@ export class PushHandler {
|
||||
|
||||
async push (email: GoogleEmail, mode: 'events' | 'calendar', calendarId?: string): Promise<void> {
|
||||
const tokens = await getUserByEmail(email)
|
||||
this.ctx.info('push', { email, mode, calendarId, tokens: tokens.length })
|
||||
const workspaces = [...new Set(tokens.map((p) => p.workspace))]
|
||||
const infos = await this.accountClient.getWorkspacesInfo(workspaces)
|
||||
for (const token of tokens) {
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { AccountClient } from '@hcengineering/account-client'
|
||||
import calendar, {
|
||||
Calendar,
|
||||
Event,
|
||||
ExternalCalendar,
|
||||
ReccuringEvent,
|
||||
ReccuringInstance,
|
||||
Visibility
|
||||
} from '@hcengineering/calendar'
|
||||
import contact, { Contact, getPersonRefsBySocialIds, Person } from '@hcengineering/contact'
|
||||
import core, {
|
||||
AttachedData,
|
||||
Data,
|
||||
@@ -27,24 +37,14 @@ import core, {
|
||||
TxOperations,
|
||||
TxProcessor
|
||||
} from '@hcengineering/core'
|
||||
import { getCalendarsSyncHistory, getEventHistory, setCalendarsSyncHistory, setEventHistory } from './kvsUtils'
|
||||
import { GoogleEmail, Token, User } from './types'
|
||||
import { calendar_v3 } from 'googleapis'
|
||||
import { getRateLimitter, RateLimiter } from './rateLimiter'
|
||||
import calendar, {
|
||||
Calendar,
|
||||
Event,
|
||||
ExternalCalendar,
|
||||
ReccuringEvent,
|
||||
ReccuringInstance,
|
||||
Visibility
|
||||
} from '@hcengineering/calendar'
|
||||
import { parseRecurrenceStrings } from './utils'
|
||||
import setting from '@hcengineering/setting'
|
||||
import { htmlToMarkup } from '@hcengineering/text'
|
||||
import { deepEqual } from 'fast-equals'
|
||||
import contact, { Contact, getPersonRefsBySocialIds, Person } from '@hcengineering/contact'
|
||||
import setting from '@hcengineering/setting'
|
||||
import { AccountClient } from '@hcengineering/account-client'
|
||||
import { calendar_v3 } from 'googleapis'
|
||||
import { getCalendarsSyncHistory, getEventHistory, setCalendarsSyncHistory, setEventHistory } from './kvsUtils'
|
||||
import { getRateLimitter, RateLimiter } from './rateLimiter'
|
||||
import { GoogleEmail, Token, User } from './types'
|
||||
import { parseRecurrenceStrings } from './utils'
|
||||
import { WatchController } from './watch'
|
||||
|
||||
const locks = new Map<string, Promise<void>>()
|
||||
@@ -171,7 +171,19 @@ export class IncomingSyncManager {
|
||||
}
|
||||
|
||||
private async sync (calendarId: string): Promise<void> {
|
||||
this.ctx.info('Sync calendar', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
emai: this.email,
|
||||
calendarId
|
||||
})
|
||||
await this.syncEvents(calendarId)
|
||||
this.ctx.info('Sync calendar finished', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
emai: this.email,
|
||||
calendarId
|
||||
})
|
||||
const watchController = WatchController.get(this.ctx, this.accountClient)
|
||||
await this.rateLimiter.take(1)
|
||||
await watchController.addWatch(this.user, this.email, calendarId, this.googleClient)
|
||||
@@ -182,11 +194,22 @@ export class IncomingSyncManager {
|
||||
await this.getMyCalendars()
|
||||
await this.syncCalendars()
|
||||
await this.getMyCalendars()
|
||||
this.ctx.info('Sync started for calendars', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
emai: this.email,
|
||||
count: this.calendars.length
|
||||
})
|
||||
for (const calendar of this.calendars) {
|
||||
if (calendar.externalId !== undefined) {
|
||||
await this.sync(calendar.externalId)
|
||||
}
|
||||
}
|
||||
this.ctx.info('Incoming sync finished', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
emai: this.email
|
||||
})
|
||||
} catch (err) {
|
||||
this.ctx.error('Start sync error', { workspace: this.user.workspace, user: this.user.userId, err })
|
||||
}
|
||||
@@ -565,7 +588,17 @@ export class IncomingSyncManager {
|
||||
|
||||
async syncCalendars (): Promise<void> {
|
||||
const history = await getCalendarsSyncHistory(this.user, this.email)
|
||||
this.ctx.info('Sync calendars', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
email: this.email
|
||||
})
|
||||
await this.calendarSync(history)
|
||||
this.ctx.info('Sync calendars finished', {
|
||||
workspace: this.user.workspace,
|
||||
user: this.user.userId,
|
||||
email: this.email
|
||||
})
|
||||
const watchController = WatchController.get(this.ctx, this.accountClient)
|
||||
await this.rateLimiter.take(1)
|
||||
await watchController.addWatch(this.user, this.email, null, this.googleClient)
|
||||
|
||||
@@ -272,6 +272,11 @@ export class WatchController {
|
||||
const key = `${CALENDAR_INTEGRATION}:watch:${email}:${calendarId ?? 'null'}`
|
||||
const exists = await client.getValue<Watch>(key)
|
||||
if (exists != null) {
|
||||
this.ctx.info('Watch already exists', {
|
||||
workspace: user.workspace,
|
||||
user: user.userId,
|
||||
calendar: calendarId
|
||||
})
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -280,6 +285,11 @@ export class WatchController {
|
||||
} else {
|
||||
await watchCalendars(email, googleClient)
|
||||
}
|
||||
this.ctx.info('Watch added', {
|
||||
workspace: user.workspace,
|
||||
user: user.userId,
|
||||
calendar: calendarId
|
||||
})
|
||||
} catch (err: any) {
|
||||
this.ctx.error('Watch add error', {
|
||||
workspace: user.workspace,
|
||||
|
||||
Reference in New Issue
Block a user