11import { AccountClient } from '@hcengineering/account-client'
2- import { generateId , isActiveMode , PersonId , WorkspaceUuid } from '@hcengineering/core'
2+ import { generateId , isActiveMode , MeasureContext , PersonId , WorkspaceUuid } from '@hcengineering/core'
33import { Credentials , OAuth2Client } from 'google-auth-library'
44import { calendar_v3 } from 'googleapis'
55import config from './config'
@@ -151,15 +151,18 @@ export class WatchController {
151151 private timer : NodeJS . Timeout | undefined = undefined
152152 protected static _instance : WatchController
153153
154- private constructor ( private readonly accountClient : AccountClient ) {
155- console . log ( 'watch started' )
154+ private constructor (
155+ private readonly ctx : MeasureContext ,
156+ private readonly accountClient : AccountClient
157+ ) {
158+ this . ctx . info ( 'watch started' )
156159 }
157160
158- static get ( accountClient : AccountClient ) : WatchController {
161+ static get ( ctx : MeasureContext , accountClient : AccountClient ) : WatchController {
159162 if ( WatchController . _instance !== undefined ) {
160163 return WatchController . _instance
161164 }
162- return new WatchController ( accountClient )
165+ return new WatchController ( ctx , accountClient )
163166 }
164167
165168 private async getUserWatches ( userId : PersonId , workspace : WorkspaceUuid ) : Promise < Record < string , Watch > > {
@@ -213,7 +216,7 @@ export class WatchController {
213216 toRefresh . push ( watch )
214217 }
215218 }
216- console . log ( 'watch, found for update' , toRefresh . length )
219+ this . ctx . info ( 'watch, found for update' , { count : toRefresh . length } )
217220 if ( toRefresh . length === 0 ) return
218221 const groups = new Map < string , WatchBase [ ] > ( )
219222 const workspaces = new Set < WorkspaceUuid > ( )
@@ -255,7 +258,7 @@ export class WatchController {
255258 await watchClient . subscribe ( group )
256259 } catch { }
257260 }
258- console . log ( 'watch check done' )
261+ this . ctx . info ( 'watch check done' )
259262 }
260263
261264 async addWatch (
@@ -280,7 +283,12 @@ export class WatchController {
280283 await watchCalendars ( user , email , googleClient )
281284 }
282285 } catch ( err : any ) {
283- console . error ( 'Watch add error' , user . workspace , user . userId , calendarId , err )
286+ this . ctx . error ( 'Watch add error' , {
287+ workspace : user . workspace ,
288+ user : user . userId ,
289+ calendar : calendarId ,
290+ err : err . message
291+ } )
284292 }
285293 }
286294}
0 commit comments