Skip to content

Commit 7132fe9

Browse files
authored
Fixed strict option not working (apache#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
1 parent e248a56 commit 7132fe9

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ January 1, 2019, 00:00:00 UTC and will stop firing January 31, 2019, 23:59:00 UT
132132

133133
- If it's true, the Trigger will fire at the top of the hour/minute (\**:**:00).
134134
- Otherwise, the Trigger will fire after the specific seconds (\**:**:00-59).
135+
- If you do not set this value, it is set to the default chosen by the operator.
136+
- Optionally, string values, `"true"` and `"false"` are also recognized as boolean values.
135137

136138
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.
137139

action/alarmWebAction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function main(params) {
103103
}
104104
newTrigger.cron = params.cron;
105105
newTrigger.timezone = params.timezone;
106-
newTrigger.strict = params.strict === 'true';
106+
newTrigger.strict = params.strict;
107107
} catch(ex) {
108108
var message = ex.message !== 'Invalid timezone.' ? `cron pattern '${params.cron}' is not valid` : ex.message;
109109
return common.sendError(400, message);

provider/lib/cronAlarm.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = function(logger, newTrigger) {
2323

2424
var maxTriggers = newTrigger.maxTriggers || constants.DEFAULT_MAX_TRIGGERS;
2525
var delayLimit = validateLimit(parseInt(process.env.ALARM_DELAY_LIMIT)) || 0;
26+
var delayDefaultStrict = process.env.ALARM_DELAY_DEFAULT_STRICT || false;
2627

2728
var cachedTrigger = {
2829
apikey: newTrigger.apikey,
@@ -104,7 +105,7 @@ module.exports = function(logger, newTrigger) {
104105
var method = "distributeCronAlarm";
105106

106107
var cronFields = (trigger.cron + '').trim().split(/\s+/);
107-
if (trigger.strict !== 'true' && cronFields.length === 5 && delayLimit !== 0) {
108+
if (!isStrict(trigger.strict) && cronFields.length === 5 && delayLimit !== 0) {
108109
var newCron = [hashName(trigger.name), ...cronFields].join(' ');
109110
logger.info(method, trigger.triggerID, 'is converted to', '"' + newCron + '"');
110111
return newCron;
@@ -123,4 +124,24 @@ module.exports = function(logger, newTrigger) {
123124
return limit;
124125
}
125126

127+
function isStrict(strict) {
128+
/**
129+
* If the strict variable is not passed from alarmWebAction(User doesn't define strict value),
130+
* then the ALARM_DELAY_DEFAULT_STRICT environment variable value is used.
131+
*/
132+
if(strict === undefined || strict === null) {
133+
return delayDefaultStrict;
134+
}
135+
136+
/**
137+
* "true"(string) -> true
138+
* "false"(string) -> false
139+
* "True"(string) -> true
140+
* "False"(string) -> false
141+
* true(boolean) -> true
142+
* false(boolean) -> false
143+
*/
144+
return String(strict).toLowerCase() === "true";
145+
}
146+
126147
};

0 commit comments

Comments
 (0)