Creating a Custom Hook Module
Custom Hook Modules
A custom hook allows you to perform tasks that are outside the scope of Data Hub. Custom hook modules can run immediately before (pre-step hook) or immediately after (post-step hook) the step's core processes.
A step is generally processed as follows:
- The selected data is read from the source database.
- The pre-step hook module runs, if any.
- The main step module runs. This can be a default Data Hub step functionality or a custom step module.
- The post-step hook module runs, if any.
- The processed data is written to the target database.
A custom hook is added as a node to the step's JSON structure:
- QS format: In the flow configuration file.
- HC format: In the step configuration file.
If a process in the custom hook module conflicts with a process in the step's core module or functionality, the core module or functionality overrides the hook module's conflicting process.
Each custom hook module is executed in its own environment, separate from Data Hub processes and other modules.
Custom hooks can be added to any type of step (ingestion, mapping, matching, merging, mastering, or custom).
Store all your custom modules under your-project-root/src/main/ml-modules/root/custom-modules. The Gradle task mlDeploy deploys the contents of that directory to the MODULES database.
Required Inputs and Outputs
A custom hook module does not require specific inputs or outputs. However, it can access some information by declaring and using the following variables in the code.
// A custom hook module receives values for the following parameters via Data Hub. You can declare only the ones you need and ignore the rest. var uris; // An array of one or more URIs being processed. var content; // An array of objects that represent each document being processed. var options; // The Options object passed to the step by Data Hub. var flowName; // The name of the flow being processed. var stepNumber; // The index of the step within the flow being processed. The stepNumber of the first step is 1. var step; // The step object. var database; // The target database.
After creating your custom hook module, add a custom hook to your step in the flow and and specify the path to your new custom hook module.