-
Notifications
You must be signed in to change notification settings - Fork 5k
[BUG] The shellTask scheduler reruns the date expression in the script to the current system time #3177
Description
Describe the bug
look at the code shows that parameter parsing is done internally twice, the first parsing takes the time expression into the current running time because there is no schedule.time in paramsMap
查看代码可以知道在内部做了两次的参数解析,第一次的解析会把时间表达式处理成运行的当前时间,因为paramsMap中并没有schedule.time
To Reproduce
1.new process
2.add shell task with script:echo "$[yyyy-MM-dd HH:mm:ss]"
3.Configure scheduling task with cron : 0 * * * * ? *
4.Wait for a scheduling task to complete ( workflow instance run in 2020-01-02 12:01:00)
5.Rerun the workflow instance (workflow instance rerun in 2020-01-02 12:10:01)
6.View the log data, will see that the output is the time the workflow was rerun ;(log prints "2020-01-02 12:10:01")
Expected behavior
The log prints the scheduled time (log output ”2020-01-02 12:01:00“ instead of ”2020-01-02 12:10:01“ )
/**
* combining local and global parameters
*/
Map<String, Property> paramsMap = ParamUtils.convert(ParamUtils.getUserDefParamsMap(taskExecutionContext.getDefinedParams()),
taskExecutionContext.getDefinedParams(),
shellParameters.getLocalParametersMap(),
CommandType.of(taskExecutionContext.getCmdTypeIfComplement()),
taskExecutionContext.getScheduleTime());
if (paramsMap != null){
//paramsMap可能为空,并且ParameterUtils.convertParameterPlaceholders方法使用了system.datetime解析[yyyyMM],第二次的schedule.time总是用不到
script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap));
}
// new
// replace variable TIME with $[YYYYmmddd...] in shell file when history run job and batch complement job
if (paramsMap != null) {
if (taskExecutionContext.getScheduleTime() != null) {
String dateTime = DateUtils.format(taskExecutionContext.getScheduleTime(), Constants.PARAMETER_FORMAT_TIME);
Property p = new Property();
p.setValue(dateTime);
p.setProp(Constants.PARAMETER_SHECDULE_TIME);
paramsMap.put(Constants.PARAMETER_SHECDULE_TIME, p);
}
script = ParameterUtils.convertParameterPlaceholders2(script, ParamUtils.convert(paramsMap));
}
Which version of Dolphin Scheduler:
-[1.3.1-release]
Requirement or improvement
remove the code
if (paramsMap != null){
script = ParameterUtils.convertParameterPlaceholders(script, ParamUtils.convert(paramsMap));
}