This is an automated email from the ASF dual-hosted git repository.
csantanapr pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-alarms.git
The following commit(s) were added to refs/heads/master by this push:
new d5d758b support timezone param for cron alarm (#170)
d5d758b is described below
commit d5d758b55515d00fcbba4231fe1231dcdc6d20c2
Author: Jason Peterson <[email protected]>
AuthorDate: Fri Dec 7 13:03:44 2018 -0500
support timezone param for cron alarm (#170)
---
.gitignore | 1 +
Dockerfile | 2 +-
README.md | 2 ++
action/alarmWebAction.js | 8 +++++---
action/alarmWeb_package.json | 2 +-
installCatalog.sh | 2 +-
package.json | 4 ++--
provider/lib/cronAlarm.js | 6 ++++--
provider/lib/dateAlarm.js | 3 ++-
provider/lib/intervalAlarm.js | 3 ++-
provider/lib/utils.js | 31 ++++++++++++++++++-------------
11 files changed, 39 insertions(+), 25 deletions(-)
diff --git a/.gitignore b/.gitignore
index 7d8681d..c848c58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@ node_modules/
.vscode
action/*.zip
action/package.json
+package-lock.json
# Eclipse
bin/
diff --git a/Dockerfile b/Dockerfile
index 0ce1fc9..9699608 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM node:8.12.0
+FROM node:8.14.0
# only package.json
ADD package.json /
diff --git a/README.md b/README.md
index e73f7ed..b742230 100644
--- a/README.md
+++ b/README.md
@@ -105,6 +105,8 @@ For more information, see: http://crontab.org. The
following strings are example
- `trigger_payload` (*optional*): The value of this parameter becomes the
content of the Trigger every time the Trigger is fired.
+- `timezone` (*optional*): This will modify the actual time relative to the
specified timezone. If the timezone is invalid, an error is thrown. You can
check all timezones available at the Moment Timezone Website
(http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/).
+
- `startDate` (*optional*): The date when the Trigger will start running. The
Trigger fires based on the schedule specified by the cron parameter.
- `stopDate` (*optional*): The date when the Trigger will stop running.
Triggers are no longer fired once this date is reached.
diff --git a/action/alarmWebAction.js b/action/alarmWebAction.js
index aae0259..5d6b8e4 100644
--- a/action/alarmWebAction.js
+++ b/action/alarmWebAction.js
@@ -38,7 +38,8 @@ function main(params) {
status: {
'active': true,
'dateChanged': Date.now()
- }
+ },
+ timezone: params.timezone
};
if (params.fireOnce) {
@@ -82,14 +83,15 @@ function main(params) {
}
try {
- cronHandle = new CronJob(params.cron, function() {});
+ cronHandle = new CronJob(params.cron, function() {},
undefined, false, params.timezone);
//validate cron granularity if 5 fields are allowed
instead of 6
if (params.limitCronFields &&
hasSecondsGranularity(params.cron)) {
return common.sendError(400, 'cron pattern is limited
to 5 fields with 1 minute as the finest granularity');
}
newTrigger.cron = params.cron;
} catch(ex) {
- return common.sendError(400, `cron pattern
'${params.cron}' is not valid`);
+ var message = ex.message !== 'Invalid timezone.' ? `cron
pattern '${params.cron}' is not valid` : ex.message;
+ return common.sendError(400, message);
}
}
diff --git a/action/alarmWeb_package.json b/action/alarmWeb_package.json
index d0806b9..cd4b6fd 100644
--- a/action/alarmWeb_package.json
+++ b/action/alarmWeb_package.json
@@ -3,6 +3,6 @@
"version": "1.0.0",
"main": "alarmWebAction.js",
"dependencies" : {
- "cron": "1.4.1"
+ "cron": "1.5.0"
}
}
diff --git a/installCatalog.sh b/installCatalog.sh
index 01dff74..c2882a0 100755
--- a/installCatalog.sh
+++ b/installCatalog.sh
@@ -84,7 +84,7 @@ zip -r alarmFeed.zip lib package.json alarm.js
$WSK_CLI -i --apihost "$EDGEHOST" action update --kind
"$ACTION_RUNTIME_VERSION" --auth "$AUTH" alarms/alarm
"$PACKAGE_HOME/action/alarmFeed.zip" \
-a description 'Fire trigger when alarm occurs' \
- -a parameters '[ {"name":"cron", "required":true}, {"name":"startDate",
"required":false}, {"name":"stopDate", "required":false} ]' \
+ -a parameters '[ {"name":"cron", "required":true}, {"name":"timezone",
"required":false}, {"name":"startDate", "required":false}, {"name":"stopDate",
"required":false} ]' \
-a feed true
$WSK_CLI -i --apihost "$EDGEHOST" action update --kind
"$ACTION_RUNTIME_VERSION" --auth "$AUTH" alarms/once
"$PACKAGE_HOME/action/alarmFeed.zip" \
diff --git a/package.json b/package.json
index 46c8b87..fdc2d22 100755
--- a/package.json
+++ b/package.json
@@ -6,10 +6,10 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.15.0",
- "cron": "1.4.1",
+ "cron": "1.5.0",
"express": "^4.13.4",
"lodash": "^4.5.0",
- "nano": "6.4.2",
+ "nano": "6.4.4",
"request": "^2.69.0",
"winston": "^2.1.1",
"moment": "^2.12.0",
diff --git a/provider/lib/cronAlarm.js b/provider/lib/cronAlarm.js
index b811ce1..6be0d6e 100644
--- a/provider/lib/cronAlarm.js
+++ b/provider/lib/cronAlarm.js
@@ -15,9 +15,11 @@ module.exports = function(logger, newTrigger) {
namespace: newTrigger.namespace,
payload: newTrigger.payload,
cron: newTrigger.cron,
+ timezone: newTrigger.timezone,
triggerID: newTrigger.triggerID,
uri: newTrigger.uri,
- monitor: newTrigger.monitor
+ monitor: newTrigger.monitor,
+ additionalData: newTrigger.additionalData
};
this.scheduleAlarm = function(triggerIdentifier, callback) {
@@ -26,7 +28,7 @@ module.exports = function(logger, newTrigger) {
try {
return new Promise(function(resolve, reject) {
- var cronHandle = new CronJob(newTrigger.cron, callback);
+ var cronHandle = new CronJob(newTrigger.cron, callback,
undefined, false, newTrigger.timezone);
if (newTrigger.stopDate) {
cachedTrigger.stopDate = newTrigger.stopDate;
diff --git a/provider/lib/dateAlarm.js b/provider/lib/dateAlarm.js
index 921ebcf..b29d7a9 100644
--- a/provider/lib/dateAlarm.js
+++ b/provider/lib/dateAlarm.js
@@ -14,7 +14,8 @@ module.exports = function(logger, newTrigger) {
deleteAfterFire: newTrigger.deleteAfterFire,
triggerID: newTrigger.triggerID,
uri: newTrigger.uri,
- monitor: newTrigger.monitor
+ monitor: newTrigger.monitor,
+ additionalData: newTrigger.additionalData
};
this.scheduleAlarm = function(triggerIdentifier, callback) {
diff --git a/provider/lib/intervalAlarm.js b/provider/lib/intervalAlarm.js
index 34d2cf9..6760bcd 100644
--- a/provider/lib/intervalAlarm.js
+++ b/provider/lib/intervalAlarm.js
@@ -14,7 +14,8 @@ module.exports = function(logger, newTrigger) {
minutes: newTrigger.minutes,
triggerID: newTrigger.triggerID,
uri: newTrigger.uri,
- monitor: newTrigger.monitor
+ monitor: newTrigger.monitor,
+ additionalData: newTrigger.additionalData
};
this.scheduleAlarm = function(triggerIdentifier, callback) {
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index b62f31b..d70881b 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -100,11 +100,18 @@ module.exports = function(logger, triggerDB, redisClient)
{
json: triggerData.payload
}, function(error, response) {
try {
+ var statusCode;
+ if (!error) {
+ statusCode = response.statusCode;
+ }
+ else if (error.statusCode) {
+ statusCode = error.statusCode;
+ }
var triggerIdentifier = triggerData.triggerID;
- logger.info(method, triggerIdentifier, 'http post request,
STATUS:', response ? response.statusCode : undefined);
+ logger.info(method, triggerIdentifier, 'http post request,
STATUS:', statusCode);
- if (error || response.statusCode >= 400) {
- logger.error(method, 'there was an error invoking',
triggerIdentifier, response ? response.statusCode : error);
+ if (error || statusCode >= 400) {
+ logger.error(method, 'there was an error invoking',
triggerIdentifier, statusCode || error);
var throttleCounter = throttleCount || 0;
// only manage trigger fires if they are not infinite
@@ -112,15 +119,15 @@ module.exports = function(logger, triggerDB, redisClient)
{
triggerData.triggersLeft++;
}
- if (!error &&
shouldDisableTrigger(response.statusCode)) {
+ if (!error && shouldDisableTrigger(statusCode)) {
//disable trigger
- var message = 'Automatically disabled after
receiving a ' + response.statusCode + ' status code when firing the trigger';
- disableTrigger(triggerIdentifier,
response.statusCode, message);
- reject('Disabled trigger ' + triggerIdentifier + '
due to status code: ' + response.statusCode);
+ var message = 'Automatically disabled after
receiving a ' + statusCode + ' status code when firing the trigger';
+ disableTrigger(triggerIdentifier, statusCode,
message);
+ reject('Disabled trigger ' + triggerIdentifier + '
due to status code: ' + statusCode);
}
else {
if (retryCount < retryAttempts) {
- throttleCounter = response &&
response.statusCode === HttpStatus.TOO_MANY_REQUESTS ? throttleCounter + 1 :
throttleCounter;
+ throttleCounter = statusCode ===
HttpStatus.TOO_MANY_REQUESTS ? throttleCounter + 1 : throttleCounter;
logger.info(method, 'attempting to fire
trigger again', triggerIdentifier, 'Retry Count:', (retryCount + 1));
setTimeout(function () {
postTrigger(triggerData, (retryCount + 1),
throttleCounter)
@@ -289,8 +296,7 @@ module.exports = function(logger, triggerDB, redisClient) {
var uri = self.uriHost + '/api/v1/namespaces/' +
namespace + '/triggers/' + name;
logger.info(method, 'Checking if trigger',
triggerIdentifier, 'still exists');
- var cachedTrigger = self.triggers[triggerIdentifier] =
{apikey: doc.apikey, additionalData: doc.additionalData};
- self.authRequest(cachedTrigger, {
+ self.authRequest(doc, {
method: 'get',
url: uri
}, function (error, response) {
@@ -302,8 +308,8 @@ module.exports = function(logger, triggerDB, redisClient) {
}
else {
createTrigger(triggerIdentifier, doc)
- .then(newTrigger => {
- Object.assign(cachedTrigger, newTrigger);
+ .then(cachedTrigger => {
+ self.triggers[triggerIdentifier] =
cachedTrigger;
logger.info(method, triggerIdentifier,
'created successfully');
if (cachedTrigger.intervalHandle &&
shouldFireTrigger(cachedTrigger)) {
try {
@@ -358,7 +364,6 @@ module.exports = function(logger, triggerDB, redisClient) {
if ((!doc.status || doc.status.active === true) &&
(!doc.monitor || doc.monitor === self.host)) {
createTrigger(triggerIdentifier, doc)
.then(cachedTrigger => {
- cachedTrigger.additionalData = doc.additionalData;
self.triggers[triggerIdentifier] = cachedTrigger;
logger.info(method, triggerIdentifier, 'created
successfully');