Risk notification package consits of one sequence named riskNotificationFlow
.
For deploying please follow these steps:
- target/create namespace
- create required cloudant-bindings
- deploying the Risk Notifier actions/sequences
- deploying trigger
Pre-requisite:
- Install IBM cloud CLI
- Setting up CLI environment.
- Deployment of risk-calulation package
This is a repeat of deployment of risk calculation package, please check it for target namespace and cloudant binding.
Use the CLI to deploy the Risk Notifier template.
-
Deploy the template. You must include a package name to contain your action. Replace with a custom name for your package.
PACKAGE_NAME=<name> ibmcloud fn deploy -m manifest.yaml
Sample
PACKAGE_NAME= risk-notifier ibmcloud fn deploy -m manifest.yaml
After the template deploys, you can make further edits to the code to customize it as needed, or go back and check out the catalog of available templates.
-
Create an action by running the ibmcloud fn action create command.
ibmcloud fn action create <action_name> <file> --kind <runtime>
Samples
cd create-notification/runtimes/actions/riskNotificationFlow ibmcloud fn action create prepareRelatedData_ReadAsset prepareRelatedData_ReadAsset.py --kind python:3.7 ibmcloud fn action create createRiskNotification createRiskNotification.py --kind python:3.7 ibmcloud fn action create formatDataToWrite formatDataToWrite.py --kind python:3.7
-
Verify that the actions are in your actions list.
ibmcloud fn action list
-
Create a sequence from the CLI with the ibmcloud fn action create command.
ibmcloud fn action create <sequence_name> --sequence <action_1>,<action_2>
Sample: sequence name is riskNotificationFlow
ibmcloud fn action create riskNotificationFlow --sequence /_/myCloudant/read,prepareRelatedData_ReadAsset,createRiskNotification,formatDataToWrite,/_/myCloudant/write
-
Triggers must be created directly within a namespace and can't be created inside packages. This trigger detects change in Cloudant DB.
- Pre-requisite: IBM Cloudant instance. To create an instance, see Getting started with IBM Cloudant.
Create a /whisk.system/cloudant package binding that is configured for your IBM Cloudant account. In this example, the package name is myCloudant, followed by trigger named
trigger_log_risk_calculation_change
Sample
ibmcloud fn package bind /whisk.system/cloudant myCloudant ibmcloud fn trigger create trig_log_risk_calc_change --feed /_/myCloudant/changes \ --param dbname log-risk-calculation \ --param filter "mailbox/by_status" \ --param query_params '{"status":"new"}'
Example output
ok: created trigger trig_log_risk_calc_change
-
Verify that the trigger is created.
ibmcloud fn trigger list
Example output
triggers /NAMESPACE/trig_log_risk_calc_change private
Next, you can test the trigger or create a rule to associate the trigger with an action.
-
Set rule to conect trigger to sequence Create a rule that invokes the riskNotificationFlow sequence every time the trig_log_risk_calc_change trigger gets fired.
ibmcloud fn rule create ruleRN trig_log_risk_calc_change riskNotificationFlow
Example output
ok: created rule ruleRN
-
Check that the action is being invoked by polling for activation logs.
ibmcloud fn activation poll
You can see that the activations occur every minute for the trigger, the rule, and the action.