Aggregation Methods
The Script Aggregator function inherits all functions and variables from the Script function and also has an object of its own called session
, which is a representation of a group of data records matching the configured conditions.
You can use the following properties/objects when configuring aggregation with the session
object:
Properties | Methods |
---|---|
|
Syntax await session.push(
excludeCurrentPayload?: boolean, flushType?: string
) if (!session.data.myCounter) {
session.data.myCounter = 0;
}
session.data.myCounter += 1;
await session.push();
/*
## 1 ##
OUTPUT:
payload -> { myCounter: 1 }
meta -> {
count: 1,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.242Z'
}
SESSION in store: {
data: {
myCounter: 1,
}
meta: {
count: 1,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.242Z'
}
}
## 2 ##
OUTPUT:
payload -> { myCounter: 2 }
meta -> {
count: 2,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.553Z'
}
SESSION in store: {
data: {
myCounter: 2,
}
meta: {
count: 2,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.553Z'
}
}
*\
Note!Flush does not happen automatically, you have to add it in your JavaScript configuration. It is recommended to keep flush in the On Timeout block. If you have a batch stream, On Timeout is triggered for sessions that have timed out when the stream is executed. If you have a real-time stream, the On Timeout is triggered for sessions that have timed out every 60 seconds. If Syntax
|
Â