@@ -3,6 +3,7 @@ import { KnownEventDataKeys } from "../../models/Event.js";
33import { getHashCode } from "../../Utils.js" ;
44import { EventPluginContext } from "../EventPluginContext.js" ;
55import { IEventPlugin } from "../IEventPlugin.js" ;
6+ import { PluginContext } from "../PluginContext.js" ;
67
78export class DuplicateCheckerPlugin implements IEventPlugin {
89 public priority : number = 1010 ;
@@ -11,6 +12,7 @@ export class DuplicateCheckerPlugin implements IEventPlugin {
1112 private _mergedEvents : MergedEvent [ ] = [ ] ;
1213 private _processedHashCodes : TimestampedHash [ ] = [ ] ;
1314 private _getCurrentTime : ( ) => number ;
15+ private _intervalId : any ;
1416 private _interval : number ;
1517
1618 constructor (
@@ -19,13 +21,23 @@ export class DuplicateCheckerPlugin implements IEventPlugin {
1921 ) {
2022 this . _getCurrentTime = getCurrentTime ;
2123 this . _interval = interval ;
24+ }
2225
23- // TODO: Can we pause this? What about on shutdown,
24- setInterval ( ( ) => {
26+ public startup ( context : PluginContext ) : Promise < void > {
27+ this . _intervalId = clearInterval ( this . _intervalId ) ;
28+ this . _intervalId = setInterval ( ( ) => {
2529 while ( this . _mergedEvents . length > 0 ) {
2630 this . _mergedEvents . shift ( ) . resubmit ( ) ;
2731 }
28- } , interval ) ;
32+ } , this . _interval ) ;
33+
34+ return Promise . resolve ( ) ;
35+ }
36+
37+ public suspend ( context : PluginContext ) : Promise < void > {
38+ this . _intervalId = clearInterval ( this . _intervalId ) ;
39+ // TODO: Resubmit events.
40+ return Promise . resolve ( ) ;
2941 }
3042
3143 public run ( context : EventPluginContext ) : Promise < void > {
@@ -50,9 +62,7 @@ export class DuplicateCheckerPlugin implements IEventPlugin {
5062 const count = context . event . count || 1 ;
5163 const now = this . _getCurrentTime ( ) ;
5264
53- const merged = this . _mergedEvents . filter ( ( s ) =>
54- s . hashCode === hashCode
55- ) [ 0 ] ;
65+ const merged = this . _mergedEvents . filter ( ( s ) => s . hashCode === hashCode ) [ 0 ] ;
5666 if ( merged ) {
5767 merged . incrementCount ( count ) ;
5868 merged . updateDate ( context . event . date ) ;
@@ -72,9 +82,7 @@ export class DuplicateCheckerPlugin implements IEventPlugin {
7282 }
7383
7484 if ( ! context . cancelled ) {
75- context . log . trace (
76- "Enqueueing event with hash: " + hashCode + "to cache." ,
77- ) ;
85+ context . log . trace ( `Enqueueing event with hash: ${ hashCode } to cache` ) ;
7886 this . _processedHashCodes . push ( { hash : hashCode , timestamp : now } ) ;
7987
8088 // Only keep the last 50 recent errors.
0 commit comments