@@ -91,6 +91,8 @@ export type ZodWorkerCleanupOptions = {
91
91
taskOptions ?: CronItemOptions ;
92
92
} ;
93
93
94
+ type ZodWorkerReporter = ( event : string , properties : Record < string , any > ) => Promise < void > ;
95
+
94
96
export type ZodWorkerOptions < TMessageCatalog extends MessageCatalogSchema > = {
95
97
name : string ;
96
98
runnerOptions : RunnerOptions ;
@@ -99,7 +101,7 @@ export type ZodWorkerOptions<TMessageCatalog extends MessageCatalogSchema> = {
99
101
tasks : ZodTasks < TMessageCatalog > ;
100
102
recurringTasks ?: ZodRecurringTasks ;
101
103
cleanup ?: ZodWorkerCleanupOptions ;
102
- reporter ?: ( subject : string , message : string ) => Promise < void > ;
104
+ reporter ?: ZodWorkerReporter ;
103
105
} ;
104
106
105
107
export class ZodWorker < TMessageCatalog extends MessageCatalogSchema > {
@@ -111,7 +113,7 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
111
113
#recurringTasks?: ZodRecurringTasks ;
112
114
#runner?: GraphileRunner ;
113
115
#cleanup: ZodWorkerCleanupOptions | undefined ;
114
- #reporter?: ( subject : string , message : string ) => Promise < void > ;
116
+ #reporter?: ZodWorkerReporter ;
115
117
116
118
constructor ( options : ZodWorkerOptions < TMessageCatalog > ) {
117
119
this . #name = options . name ;
@@ -528,10 +530,11 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
528
530
} ) ;
529
531
530
532
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
+ } ) ;
535
538
}
536
539
}
537
540
@@ -581,10 +584,11 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
581
584
payload,
582
585
} ) ;
583
586
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
+ } ) ;
588
592
}
589
593
590
594
#logDebug( message : string , args ?: any ) {
0 commit comments