You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by st...@apache.org on 2020/03/18 03:26:30 UTC

[openwhisk-package-alarms] branch master updated: Fixed strict option not working (#208)

This is an automated email from the ASF dual-hosted git repository.

style95 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-package-alarms.git


The following commit(s) were added to refs/heads/master by this push:
     new 7132fe9  Fixed strict option not working (#208)
7132fe9 is described below

commit 7132fe939a20ef54bae0516644c2fb964113ba8e
Author: 김건희 <ki...@gmail.com>
AuthorDate: Tue Mar 17 20:26:20 2020 -0700

    Fixed strict option not working (#208)
    
    * Fix for comparing boolean values to string
    
    * Add default value to strict option
    
    * Update documents for strict option
    
    * Update user guide for strict parameter
---
 README.md                 |  2 ++
 action/alarmWebAction.js  |  2 +-
 provider/lib/cronAlarm.js | 23 ++++++++++++++++++++++-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 7c3fcc6..891a401 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,8 @@ January 1, 2019, 00:00:00 UTC and will stop firing January 31, 2019, 23:59:00 UT
 
   - If it's true, the Trigger will fire at the top of the hour/minute (\**:**:00).
   - Otherwise, the Trigger will fire after the specific seconds (\**:**:00-59).
+  - If you do not set this value, it is set to the default chosen by the operator.
+  - Optionally, string values, `"true"` and `"false"` are also recognized as boolean values.
 
 The delay is determined by the hash value of the Trigger's name, so it keeps the same interval before and after the (re)deployment.
 
diff --git a/action/alarmWebAction.js b/action/alarmWebAction.js
index b2e9bf2..b6145f9 100644
--- a/action/alarmWebAction.js
+++ b/action/alarmWebAction.js
@@ -103,7 +103,7 @@ function main(params) {
                     }
                     newTrigger.cron = params.cron;
                     newTrigger.timezone = params.timezone;
-                    newTrigger.strict = params.strict === 'true';
+                    newTrigger.strict = params.strict;
                 } catch(ex) {
                     var message = ex.message !== 'Invalid timezone.' ? `cron pattern '${params.cron}' is not valid` : ex.message;
                     return common.sendError(400, message);
diff --git a/provider/lib/cronAlarm.js b/provider/lib/cronAlarm.js
index ef26668..07053e7 100644
--- a/provider/lib/cronAlarm.js
+++ b/provider/lib/cronAlarm.js
@@ -23,6 +23,7 @@ module.exports = function(logger, newTrigger) {
 
     var maxTriggers = newTrigger.maxTriggers || constants.DEFAULT_MAX_TRIGGERS;
     var delayLimit = validateLimit(parseInt(process.env.ALARM_DELAY_LIMIT)) || 0;
+    var delayDefaultStrict = process.env.ALARM_DELAY_DEFAULT_STRICT || false;
 
     var cachedTrigger = {
         apikey: newTrigger.apikey,
@@ -104,7 +105,7 @@ module.exports = function(logger, newTrigger) {
         var method = "distributeCronAlarm";
 
         var cronFields = (trigger.cron + '').trim().split(/\s+/);
-        if (trigger.strict !== 'true' && cronFields.length === 5 && delayLimit !== 0) {
+        if (!isStrict(trigger.strict) && cronFields.length === 5 && delayLimit !== 0) {
             var newCron = [hashName(trigger.name), ...cronFields].join(' ');
             logger.info(method, trigger.triggerID, 'is converted to', '"' + newCron + '"');
             return newCron;
@@ -123,4 +124,24 @@ module.exports = function(logger, newTrigger) {
         return limit;
     }
 
+    function isStrict(strict) {
+        /**
+         * If the strict variable is not passed from alarmWebAction(User doesn't define strict value),
+         * then the ALARM_DELAY_DEFAULT_STRICT environment variable value is used.
+         */
+        if(strict === undefined || strict === null) {
+            return delayDefaultStrict;
+        }
+
+        /**
+         * "true"(string)   -> true
+         * "false"(string)  -> false
+         * "True"(string)   -> true
+         * "False"(string)  -> false
+         * true(boolean)    -> true
+         * false(boolean)   -> false
+         */
+        return String(strict).toLowerCase() === "true";
+    }
+
 };