Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You can use the following properties/objects when performing the aggregation:

Object name

Description

Properties

Methods

Session

The session object represents

the current matching aggregated data

a group of data records matching the configured conditions.

  • session.key: The id of the session constructed based on the group by rules.

  • session.data: The configurable data block of the session used for storing the aggregated data. The default value is { }.

  • session.meta: Meta data collected by the application containing:

    • count: Number of records matching the current session. The count is increased every time a  record passes. 

    • firstEvent: Timestamp for when the first record matched the session.

    • lastEvent: Timestamp for when the last record matched the session.

    • flushType: The flushType is set as part of the meta downstream once the session is either pushed or flushed.

    • mycustomProperty: Allows you to add a custom property in the meta data, that will also be pushed downstream along with the payload.

      Meta properties

      Code Block
      meta = {
        count: number,
        firstEvent: timestamp,
        lastEvent: timestamp,
        flushType: string,
        myCustomProperty: any,
      }
  • session.timeoutAt: Timestamp for when a session should be flushed. Use the methods setTimeout and clearTimeout when configuring the timeoutAt property.

  • Push: Pushes the session downstream along with its current meta data.
    If excludeCurrentPayload is set to true the pushed session will exclude the current input as part of the meta. By default, excludeCurrentPayload is false.
    The flushType argument sets the flushType property on the meta. Defaults to PUSH. 

Syntax

Code Block
await session.push(
excludeCurrentPayload?: boolean, flushType?: string
)
Expand
titleExample
Code Block
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' 
    }
  }
  
*\


  • delete: Deletes the current session. You will not be able to perform any operation on the session object after it has been deleted.

    Syntax

    Code Block
     await session.delete();
    
    // Will not push!
    await session.push();
    
    // Will not be saved!
    session.data.myProperty = 1337;
  • flush(excludeCurrentPayload?: boolean): Flushes the data and deletes the session. You will not be able to perform any operation on the session object after it has been deleted.

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 excludeCurrentPayload is set as true, the flushed session will exclude the current input as part of the meta data. excludeCurrentPayload is set to false by default. The flushType argument defines the flushType property for the meta data and is set to flush by default.

Syntax

Code Block
await session.flush(
excludeCurrentPayload?: boolean, flushType?: string
)
  • clear(): Clears the session but it is not deleted and can still be

re-used
  • used and viewed in the Aggregation Inspector.

    Code Block
    await session.clear()
  • setTimeout: A timeout can be set to trigger delayed actions. Setting a timeout on a session sets or updates the current timeout in milliseconds. The value can either be in UTC date format or string format.

Expand
titleExample
Code Block
session.setTimeout(new Date('2022-06-10T08:57:06.242Z'));

const moment = require('moment');
session.setTimeout(moment().add(1, 'days').toDate());


  • clearTimeout: Clears the timeout previously set by calling setTimeout.