@@ -91,6 +91,8 @@ export type ZodWorkerCleanupOptions = {
9191 taskOptions ?: CronItemOptions ;
9292} ;
9393
94+ type ZodWorkerReporter = ( event : string , properties : Record < string , any > ) => Promise < void > ;
95+
9496export type ZodWorkerOptions < TMessageCatalog extends MessageCatalogSchema > = {
9597 name : string ;
9698 runnerOptions : RunnerOptions ;
@@ -99,7 +101,7 @@ export type ZodWorkerOptions<TMessageCatalog extends MessageCatalogSchema> = {
99101 tasks : ZodTasks < TMessageCatalog > ;
100102 recurringTasks ?: ZodRecurringTasks ;
101103 cleanup ?: ZodWorkerCleanupOptions ;
102- reporter ?: ( subject : string , message : string ) => Promise < void > ;
104+ reporter ?: ZodWorkerReporter ;
103105} ;
104106
105107export class ZodWorker < TMessageCatalog extends MessageCatalogSchema > {
@@ -111,7 +113,7 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
111113 #recurringTasks?: ZodRecurringTasks ;
112114 #runner?: GraphileRunner ;
113115 #cleanup: ZodWorkerCleanupOptions | undefined ;
114- #reporter?: ( subject : string , message : string ) => Promise < void > ;
116+ #reporter?: ZodWorkerReporter ;
115117
116118 constructor ( options : ZodWorkerOptions < TMessageCatalog > ) {
117119 this . #name = options . name ;
@@ -528,10 +530,11 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
528530 } ) ;
529531
530532 if ( this . #reporter) {
531- await this . #reporter(
532- "Worker Queue Cleanup" ,
533- `Cleaned up ${ results . length } jobs older than ${ expirationDate . toISOString ( ) } `
534- ) ;
533+ await this . #reporter( "cleanup_stats" , {
534+ count : results . length ,
535+ expirationDate,
536+ ts : payload . _cron . ts ,
537+ } ) ;
535538 }
536539 }
537540
@@ -581,10 +584,11 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
581584 payload,
582585 } ) ;
583586
584- await this . #reporter(
585- "Worker Queue Metrics" ,
586- `Added ${ addedCountResults . count } jobs in the last hour, total jobs: ${ totalCountResults . count } `
587- ) ;
587+ await this . #reporter( "queue_metrics" , {
588+ addedCount : addedCountResults . count ,
589+ totalCount : totalCountResults . count ,
590+ ts : payload . _cron . ts ,
591+ } ) ;
588592 }
589593
590594 #logDebug( message : string , args ?: any ) {
0 commit comments