#!/bin/bash
TRIGGER_NAME="triggerInterval"
RULE_NAME="ruleInterval"
ACTION_NAME="/whisk.system/utils/date"
EVERY_MINUTES=2
# Stop date 10 minutes from now
STOP_DATE=$(date -u -v +5M +"%Y-%m-%dT%H:%M:%S")
# Clean trigger, rule
bx wsk trigger delete ${TRIGGER_NAME}
bx wsk rule delete ${RULE_NAME}
# Create trigger
bx wsk trigger create ${TRIGGER_NAME} \
--feed /whisk.system/alarms/interval \
--param minutes ${EVERY_MINUTES} \
--param stopDate ${STOP_DATE}
# Create rule
bx wsk rule update ${RULE_NAME} ${TRIGGER_NAME} ${ACTION_NAME}
echo "Created trigger ${TRIGGER_NAME} to fire every ${EVERY_MINUTES} minutes up to ${STOP_DATE}"