1. timemachine
  2. scheduler

Commits

timemachine  committed ab9f6bb

Improved DateListSchedule and ScriptingDateListProvider.

  • Participants
  • Parent commits 54a52c8
  • Branches 1.1.x

Comments (0)

Files changed (2)

File timemachine-scheduler/src/main/java/timemachine/scheduler/schedule/DateListSchedule.java

View file
 				Class<DateListProvider> cls = Utils.toClass(dateListProviderClassName);
 				DateListProvider dateListProvider = Utils.newInstance(cls);
 				result = dateListProvider.getDateList(schedule);
-				logger.debug("Generated {} dates", result.size());
+				if (logger.isDebugEnabled())
+					logger.debug("Generated: {}", result);
 			} catch (RuntimeException e) {
 				logger.error("Failed to generate new date list by provider " + dateListProviderClassName, e);
 			}

File timemachine-scheduler/src/main/java/timemachine/scheduler/schedule/ScriptingDateListProvider.java

View file
 	public void init(DateListSchedule schedule) {
 		String providerData = schedule.getDateListProviderData();
 		providerDataMap = Utils.toMap(providerData);
-		scriptEngineName = providerDataMap.get("scriptingEngineName");
+		scriptEngineName = providerDataMap.get("scriptEngineName");
 		if (scriptEngineName == null) 
 			scriptEngineName = DEFUALT_SCRIPTING_ENGINE_NAME;
 		
 		if (scriptEngine == null)
 			init(schedule);
 		
-		List<Date> result = null;
 		Bindings bindings = scriptEngine.createBindings();
 		bindings.put("dateListSchedule", schedule);
 		bindings.put("dateListProvider", this);
 
 		String scriptText = providerDataMap.get("scriptText");
 		String scriptFile = providerDataMap.get("scriptFile");
+		Object result = null;
 		if (scriptText != null) {
 			try {
-				result = (List<Date>)scriptEngine.eval(scriptText, bindings);
+				result = scriptEngine.eval(scriptText, bindings);
 			} catch (ScriptException e) {
 				throw new SchedulerException("Failed to generate date list: failed to evaluate script to date list.", e);
 			}
 				logger.debug("Reading scriptFile {}", url);
 				InputStream inStream = url.openStream();
 				reader = new InputStreamReader(inStream);
-				scriptEngine.eval(reader, bindings);
+				result = scriptEngine.eval(reader, bindings);
 			} catch (FileNotFoundException e) {
 				throw new SchedulerException("Failed to generate date list: failed to find script " + scriptFile, e);
 			} catch (ScriptException e) {
 			throw new SchedulerException("Failed to generate date list: missing scriptText or scriptFile" +
 					" in provider data map.");
 		}
-		return result;
+		
+		if (!(result instanceof List))
+			throw new SchedulerException("Failed to generate date list: script result is not a list of dates!");
+		
+		return (List<Date>)result;
 	}
 }