Event Functions

Introduction

An Event function is an asynchronous task function that is associated with an Event Listener. An Event function is created to execute a task or a set of tasks on the occurrence of a specified event.

The default Event Listener listens for an event occurring in one of the Catalyst components and the custom Event Listener listens for the invocation of a particular URL. When these events occur, the event function associated with that event listener instance is automatically invoked and executed.

You cannot invoke a Event function manually, or test it in the console. However, you can use the functions:shell command to test it in the CLI. You can also generate sample input payload for an event function using the event:generate command in the CLI to test it. The endpoint of an Event function is not accessible through a Function URL like Basic I/O or Advanced I/O functions are. An Event function does not return any response other than determining if the function execution was a success or failure.

You can create an Event function from the Catalyst console, and code it there, or use the CLI to initialize the function and deploy it to the console.

You can use various tools to manage your Event functions and view their performance statistics such as Logs or Application Performance Monitoring, as mentioned in the Functions Introduction page.

You can practice working with Event functions with the Event Function tutorial or the WorkDrive Sync App tutorial.


Event Function Modules

Java

A Catalyst Event Function supports two modules in Java: context and event.

The context module contains the following built-in methods:

  1. context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a function.
  2. context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a function, which is a constant value of 15 minutes.

The event module contains the following built-in methods:

  1. event.getAction(): To get the action executed in the Catalyst components that triggered the event in the default Event Listener, such as data insertion in a table or a user sign-up.
  2. event.getSourceEntityId(): This can be used to get the ID of the source entity where the event occurred, such as the Table ID or a cache’s Segment ID.
  3. event.getProjectDetails(): To get the project details, such as the project ID and project name.
  4. event.getData(): To get the data about the event associated with the event function.
  5. event.getTime(): To get the time of the event occurrence that invoked the event function.
  6. event.getSource(): To get the name of the source that triggered the event, such as the Data Store, Cache, Authentication, File Store, Github and web client.
  7. event.getEventBusDetails(): To get the details of the event bus such as the configured event actions and rules.

When you execute a java function, it returns the status of the execution as either SUCCESS or FAILURE at the end of its execution. The returned status is of type com.catalyst.event.EVENT_STATUS.


Node.js

A Catalyst Event Function supports two modules in Node.js: context and event.

The context module contains the following built-in methods:

  1. context.closeWithSuccess(): To indicate that the function executed successfully. You must use this at the end of the function.
  2. context.closeWithFailure(): To indicate that the function’s execution was a failure. You must use this at the end of the function.
  3. context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a function.
  4. context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a function, which is a constant value of 15 minutes.

The event module contains the following built-in methods:

  1. event.getProjectDetails(): To get the project details, such as the project ID and project name
  2. event.getData(): To get the data about the event associated with the function
  3. event.getTime(): To get the time of the event occurrence that invoked the function
  4. event.getSource(): This method is used to get the name of the source that triggered the event, such as the DataStore, Cache, Authentication, FileStore, Github and webclient.
  5. event.getEventBusDetails(): To get the details of the event bus such as the configured event actions and rules.
  6. event.getAction(): To get the action executed in the Catalyst components that triggered the event in the default Event Listener, such as data insertion in a table or a user sign-up
  7. event.getSourceEntityId(): To get the ID of the source entity where the event occurred, such as the Table ID or a cache’s Segment ID

Python

A Catalyst Event Function supports two modules in Python as well: context and event.

The context module contains the following built-in methods:

  1. context.close_with_success(): To indicate that the function executed successfully. You must use this at the end of the function.

  2. context.close_with_failure(): To indicate that the function’s execution was a failure and you must use this at the end of the function.

  3. context.get_remaining_execution_time_ms(): This can be used to fetch the remaining execution time of a function.

  4. context.get_max_execution_time_ms(): This method can be used to get the maximum execution time of a function, which is a constant value of 15 minutes.

The event module contains the following built-in methods:

  1. event.get_event_bus_details(): To get the details of the event bus such as the configured event actions and rules.
  2. event.get_project_details(): To get the project details, such as the project ID and project name.
  3. event.get_data(): To get the data about the event associated with the event function.
  4. event.get_time(): To get the time of the event occurrence that invoked the function.
  5. event.get_source(): To get the name of the source that triggered the event, such as the DataStore, Cache, Authentication, FileStore, Github and webclient.
  6. event.get_action(): To get the action executed in the Catalyst components that triggered the event in the default Event Listener, such as data insertion in a table or a user sign-up.
  7. event.get_source_entity_id(): To get the ID of the source entity where the event occurred, such as the Table ID or a cache’s Segment ID.

Last Updated 2023-10-12 19:23:27 +0530 +0530