Logs for calendar service (#7114)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-11-06 21:39:06 +05:00 committed by GitHub
parent 25445c1996
commit 43c681236b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 11 deletions

View File

@ -673,7 +673,6 @@ export class CalendarClient {
} }
private async syncEvent (calendarId: string, event: calendar_v3.Schema$Event, accessRole: string): Promise<void> { private async syncEvent (calendarId: string, event: calendar_v3.Schema$Event, accessRole: string): Promise<void> {
console.log('SYNC EVENT CALL', calendarId, JSON.stringify(event))
if (event.id != null) { if (event.id != null) {
const me = await this.getMe() const me = await this.getMe()
const calendars = this.workspace.getMyCalendars(me) const calendars = this.workspace.getMyCalendars(me)
@ -681,7 +680,6 @@ export class CalendarClient {
calendars.find((p) => p.externalId === event.organizer?.email) ?? calendars.find((p) => p.externalId === event.organizer?.email) ??
calendars.find((p) => p.externalId === calendarId) ?? calendars.find((p) => p.externalId === calendarId) ??
calendars[0] calendars[0]
console.log('Target space', _calendar)
if (_calendar !== undefined) { if (_calendar !== undefined) {
const exists = (await this.client.findOne(calendar.class.Event, { const exists = (await this.client.findOne(calendar.class.Event, {
eventId: event.id, eventId: event.id,
@ -697,9 +695,7 @@ export class CalendarClient {
} }
private async updateExtEvent (event: calendar_v3.Schema$Event, current: Event): Promise<void> { private async updateExtEvent (event: calendar_v3.Schema$Event, current: Event): Promise<void> {
console.log('UPDATE EVENT', current._id, JSON.stringify(event))
if (event.status === 'cancelled' && current._class !== calendar.class.ReccuringInstance) { if (event.status === 'cancelled' && current._class !== calendar.class.ReccuringInstance) {
console.log('REMOVE EVENT', current._id)
await this.client.remove(current) await this.client.remove(current)
return return
} }
@ -715,7 +711,6 @@ export class CalendarClient {
current as ReccuringInstance current as ReccuringInstance
) )
if (Object.keys(diff).length > 0) { if (Object.keys(diff).length > 0) {
console.log('UPDATE REC INSTANCE DIFF', JSON.stringify(diff), JSON.stringify(current))
await this.client.update(current, diff) await this.client.update(current, diff)
} }
} else { } else {
@ -731,13 +726,11 @@ export class CalendarClient {
current as ReccuringEvent current as ReccuringEvent
) )
if (Object.keys(diff).length > 0) { if (Object.keys(diff).length > 0) {
console.log('UPDATE REC EVENT DIFF', JSON.stringify(diff), JSON.stringify(current))
await this.client.update(current, diff) await this.client.update(current, diff)
} }
} else { } else {
const diff = this.getDiff(data, current) const diff = this.getDiff(data, current)
if (Object.keys(diff).length > 0) { if (Object.keys(diff).length > 0) {
console.log('UPDATE EVENT DIFF', JSON.stringify(diff), JSON.stringify(current))
await this.client.update(current, diff) await this.client.update(current, diff)
} }
} }
@ -827,7 +820,6 @@ export class CalendarClient {
} }
) )
await this.saveMixins(event, id) await this.saveMixins(event, id)
console.log('SAVE INSTANCE', id, JSON.stringify(event))
} else if (event.status !== 'cancelled') { } else if (event.status !== 'cancelled') {
if (event.recurrence != null) { if (event.recurrence != null) {
const parseRule = parseRecurrenceStrings(event.recurrence) const parseRule = parseRecurrenceStrings(event.recurrence)
@ -847,7 +839,6 @@ export class CalendarClient {
} }
) )
await this.saveMixins(event, id) await this.saveMixins(event, id)
console.log('SAVE REC EVENT', id, JSON.stringify(event))
} else { } else {
const id = await this.client.addCollection( const id = await this.client.addCollection(
calendar.class.Event, calendar.class.Event,
@ -858,7 +849,6 @@ export class CalendarClient {
data data
) )
await this.saveMixins(event, id) await this.saveMixins(event, id)
console.log('SAVE EVENT', id, JSON.stringify(event))
} }
} }
} }

View File

@ -86,7 +86,7 @@ export class CalendarController {
clearTimeout(timeout) clearTimeout(timeout)
clients.push(client) clients.push(client)
} catch (err) { } catch (err) {
console.error(`Couldn't create client for ${workspace} ${token.userId}`) console.error(`Couldn't create client for ${workspace} ${token.userId} ${token.email}`)
} }
} }
for (const client of clients) { for (const client of clients) {
@ -95,6 +95,7 @@ export class CalendarController {
}) })
} }
void workspaceClient.sync() void workspaceClient.sync()
console.log('Workspace started', workspace)
} }
push (email: string, mode: 'events' | 'calendar', calendarId?: string): void { push (email: string, mode: 'events' | 'calendar', calendarId?: string): void {

View File

@ -86,6 +86,7 @@ export class WorkspaceClient {
if (current !== undefined) return current if (current !== undefined) return current
const newClient = await CalendarClient.create(this.credentials, user, this.mongo, this.client, this) const newClient = await CalendarClient.create(this.credentials, user, this.mongo, this.client, this)
this.clients.set(user.email, newClient) this.clients.set(user.email, newClient)
console.log('create new client', user.email, this.workspace)
return newClient return newClient
} }
@ -151,6 +152,9 @@ export class WorkspaceClient {
private getCalendarClientByCalendar (id: Ref<ExternalCalendar>): CalendarClient | undefined { private getCalendarClientByCalendar (id: Ref<ExternalCalendar>): CalendarClient | undefined {
const calendar = this.calendars.byId.get(id) const calendar = this.calendars.byId.get(id)
if (calendar === undefined) {
console.log("couldn't find calendar by id", id)
}
return calendar != null ? this.clients.get(calendar.externalUser) : undefined return calendar != null ? this.clients.get(calendar.externalUser) : undefined
} }
@ -216,14 +220,17 @@ export class WorkspaceClient {
this.txHandlers.push(async (...tx: Tx[]) => { this.txHandlers.push(async (...tx: Tx[]) => {
await this.txEventHandler(...tx) await this.txEventHandler(...tx)
}) })
console.log('receive new events', this.workspace, newEvents.length)
for (const newEvent of newEvents) { for (const newEvent of newEvents) {
const client = this.getCalendarClientByCalendar(newEvent.calendar as Ref<ExternalCalendar>) const client = this.getCalendarClientByCalendar(newEvent.calendar as Ref<ExternalCalendar>)
if (client === undefined) { if (client === undefined) {
console.log('Client not found', newEvent.calendar, this.workspace)
return return
} }
await client.syncMyEvent(newEvent) await client.syncMyEvent(newEvent)
await this.updateSyncTime() await this.updateSyncTime()
} }
console.log('all messages synced', this.workspace)
} }
private async txEventHandler (...txes: Tx[]): Promise<void> { private async txEventHandler (...txes: Tx[]): Promise<void> {