@Test public void testIsQueryScheduledToRun() { Long runSchedule = 720L; String lastRunTime = "2018/07/16 05:50 PM"; assertTrue(executor.isQueryScheduledToRun(runSchedule, lastRunTime, null)); }
public Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule) { if (lastRunTime == null && (cronSchedule == null || cronSchedule.trim().length() == 0)) { return Boolean.TRUE; } ZonedDateTime dateTime = null; ZonedDateTime now = ZonedDateTime.now(InsightsUtils.zoneId); Long timeDifferenceInMinutes = null; if (lastRunTime != null && !lastRunTime.isEmpty()) { dateTime = ZonedDateTime.parse(lastRunTime, formatter); } if(cronSchedule != null && cronSchedule.trim().length() > 0) { try { CronExpression convert = new CronExpressionConverter().convert(cronSchedule); if(dateTime == null) { dateTime = now.minusDays(1); } Date cronDate = convert.getNextValidTimeAfter(Date.from(dateTime.toInstant())); if(cronDate.before(new Date())) { return Boolean.TRUE; } } catch (Exception e) { log.error("Unable to parse the CRON expression: "+cronSchedule, e); } }else { if (dateTime != null && now != null) { Duration d = Duration.between(dateTime, now); timeDifferenceInMinutes = d.abs().toMinutes(); } if (timeDifferenceInMinutes > runSchedule) { return Boolean.TRUE; } } return Boolean.FALSE; }
OfflineDataProcessingExecutor extends TimerTask { public Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule) { if (lastRunTime == null && (cronSchedule == null || cronSchedule.trim().length() == 0)) { return Boolean.TRUE; } ZonedDateTime dateTime = null; ZonedDateTime now = ZonedDateTime.now(InsightsUtils.zoneId); Long timeDifferenceInMinutes = null; if (lastRunTime != null && !lastRunTime.isEmpty()) { dateTime = ZonedDateTime.parse(lastRunTime, formatter); } if(cronSchedule != null && cronSchedule.trim().length() > 0) { try { CronExpression convert = new CronExpressionConverter().convert(cronSchedule); if(dateTime == null) { dateTime = now.minusDays(1); } Date cronDate = convert.getNextValidTimeAfter(Date.from(dateTime.toInstant())); if(cronDate.before(new Date())) { return Boolean.TRUE; } } catch (Exception e) { log.error("Unable to parse the CRON expression: "+cronSchedule, e); } }else { if (dateTime != null && now != null) { Duration d = Duration.between(dateTime, now); timeDifferenceInMinutes = d.abs().toMinutes(); } if (timeDifferenceInMinutes > runSchedule) { return Boolean.TRUE; } } return Boolean.FALSE; } }
OfflineDataProcessingExecutor extends TimerTask { public Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule) { if (lastRunTime == null && (cronSchedule == null || cronSchedule.trim().length() == 0)) { return Boolean.TRUE; } ZonedDateTime dateTime = null; ZonedDateTime now = ZonedDateTime.now(InsightsUtils.zoneId); Long timeDifferenceInMinutes = null; if (lastRunTime != null && !lastRunTime.isEmpty()) { dateTime = ZonedDateTime.parse(lastRunTime, formatter); } if(cronSchedule != null && cronSchedule.trim().length() > 0) { try { CronExpression convert = new CronExpressionConverter().convert(cronSchedule); if(dateTime == null) { dateTime = now.minusDays(1); } Date cronDate = convert.getNextValidTimeAfter(Date.from(dateTime.toInstant())); if(cronDate.before(new Date())) { return Boolean.TRUE; } } catch (Exception e) { log.error("Unable to parse the CRON expression: "+cronSchedule, e); } }else { if (dateTime != null && now != null) { Duration d = Duration.between(dateTime, now); timeDifferenceInMinutes = d.abs().toMinutes(); } if (timeDifferenceInMinutes > runSchedule) { return Boolean.TRUE; } } return Boolean.FALSE; }  }
OfflineDataProcessingExecutor extends TimerTask { public Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule) { if (lastRunTime == null && (cronSchedule == null || cronSchedule.trim().length() == 0)) { return Boolean.TRUE; } ZonedDateTime dateTime = null; ZonedDateTime now = ZonedDateTime.now(InsightsUtils.zoneId); Long timeDifferenceInMinutes = null; if (lastRunTime != null && !lastRunTime.isEmpty()) { dateTime = ZonedDateTime.parse(lastRunTime, formatter); } if(cronSchedule != null && cronSchedule.trim().length() > 0) { try { CronExpression convert = new CronExpressionConverter().convert(cronSchedule); if(dateTime == null) { dateTime = now.minusDays(1); } Date cronDate = convert.getNextValidTimeAfter(Date.from(dateTime.toInstant())); if(cronDate.before(new Date())) { return Boolean.TRUE; } } catch (Exception e) { log.error("Unable to parse the CRON expression: "+cronSchedule, e); } }else { if (dateTime != null && now != null) { Duration d = Duration.between(dateTime, now); timeDifferenceInMinutes = d.abs().toMinutes(); } if (timeDifferenceInMinutes > runSchedule) { return Boolean.TRUE; } } return Boolean.FALSE; }  @Override void run(); int executeOfflineProcessing(); Boolean hasJsonFileExtension(String fileName); Boolean processOfflineConfiguration(File jsonFile); DataEnrichmentModel updateLastExecutionTime(DataEnrichmentModel dataEnrichmentModel); Boolean executeCypherQuery(String cypherQuery, DataEnrichmentModel dataEnrichmentModel); Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule); }
OfflineDataProcessingExecutor extends TimerTask { public Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule) { if (lastRunTime == null && (cronSchedule == null || cronSchedule.trim().length() == 0)) { return Boolean.TRUE; } ZonedDateTime dateTime = null; ZonedDateTime now = ZonedDateTime.now(InsightsUtils.zoneId); Long timeDifferenceInMinutes = null; if (lastRunTime != null && !lastRunTime.isEmpty()) { dateTime = ZonedDateTime.parse(lastRunTime, formatter); } if(cronSchedule != null && cronSchedule.trim().length() > 0) { try { CronExpression convert = new CronExpressionConverter().convert(cronSchedule); if(dateTime == null) { dateTime = now.minusDays(1); } Date cronDate = convert.getNextValidTimeAfter(Date.from(dateTime.toInstant())); if(cronDate.before(new Date())) { return Boolean.TRUE; } } catch (Exception e) { log.error("Unable to parse the CRON expression: "+cronSchedule, e); } }else { if (dateTime != null && now != null) { Duration d = Duration.between(dateTime, now); timeDifferenceInMinutes = d.abs().toMinutes(); } if (timeDifferenceInMinutes > runSchedule) { return Boolean.TRUE; } } return Boolean.FALSE; }  @Override void run(); int executeOfflineProcessing(); Boolean hasJsonFileExtension(String fileName); Boolean processOfflineConfiguration(File jsonFile); DataEnrichmentModel updateLastExecutionTime(DataEnrichmentModel dataEnrichmentModel); Boolean executeCypherQuery(String cypherQuery, DataEnrichmentModel dataEnrichmentModel); Boolean isQueryScheduledToRun(Long runSchedule, String lastRunTime, String cronSchedule);  }