add missing scheduler calc of next exec_date (call of calculateAPIScheduler)

- after last_exec_date is altered, next_exec_date should be recalculated
- makes the recalculation of next_exec in advance (without api call surely made) in Switchbard.schedulerJob() obsolete
Slightly modify next_exec calc. on missed event to now+schedule_time (from fix 10min)
pull/66/head
reger 8 years ago
parent 70d47ae38a
commit 2910fe35c1

@ -80,7 +80,7 @@ public class WorkTables extends Tables {
public final static String TABLE_API_COL_APICALL_COUNT = "apicall_count"; // counts how often the API was called (starts with 1) public final static String TABLE_API_COL_APICALL_COUNT = "apicall_count"; // counts how often the API was called (starts with 1)
public final static String TABLE_API_COL_APICALL_SCHEDULE_TIME = "apicall_schedule_time"; // factor for SCHEULE_UNIT time units public final static String TABLE_API_COL_APICALL_SCHEDULE_TIME = "apicall_schedule_time"; // factor for SCHEULE_UNIT time units
public final static String TABLE_API_COL_APICALL_SCHEDULE_UNIT = "apicall_schedule_unit"; // may be 'minutes', 'hours', 'days' public final static String TABLE_API_COL_APICALL_SCHEDULE_UNIT = "apicall_schedule_unit"; // may be 'minutes', 'hours', 'days'
public final static String TABLE_API_COL_APICALL_EVENT_KIND = "apicall_event_kind"; // public final static String TABLE_API_COL_APICALL_EVENT_KIND = "apicall_event_kind"; //
public final static String TABLE_API_COL_APICALL_EVENT_ACTION = "apicall_event_action"; // public final static String TABLE_API_COL_APICALL_EVENT_ACTION = "apicall_event_action"; //
public final static String TABLE_ROBOTS_NAME = "robots"; public final static String TABLE_ROBOTS_NAME = "robots";
@ -146,6 +146,7 @@ public class WorkTables extends Tables {
// insert APICALL attributes // insert APICALL attributes
row.put(TABLE_API_COL_APICALL_COUNT, row.get(TABLE_API_COL_APICALL_COUNT, 1) + 1); row.put(TABLE_API_COL_APICALL_COUNT, row.get(TABLE_API_COL_APICALL_COUNT, 1) + 1);
calculateAPIScheduler(row, false); // set next execution time (as this might be a forward existing entry with schedule data)
super.update(TABLE_API_NAME, row); super.update(TABLE_API_NAME, row);
assert pk != null; assert pk != null;
} }
@ -311,20 +312,24 @@ public class WorkTables extends Tables {
Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, (Date) null) : null; Date date = row.containsKey(WorkTables.TABLE_API_COL_DATE) ? row.get(WorkTables.TABLE_API_COL_DATE, (Date) null) : null;
date = update ? row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, date) : row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date); date = update ? row.get(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, date) : row.get(WorkTables.TABLE_API_COL_DATE_LAST_EXEC, date);
if (date == null) return; if (date == null) return;
long d = date.getTime(); long d = 0;
final String kind = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_KIND, "off"); final String kind = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_KIND, "off");
if ("off".equals(kind)) { if ("off".equals(kind)) {
int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 1); int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, -1);
if (time <= 0) { if (time <= 0) { // no schedule time
row.put(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, ""); row.put(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, "");
return; return;
} }
String unit = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days"); String unit = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_UNIT, "days");
if (unit.equals("minutes")) d += 60000L * Math.max(10, time); if (unit.equals("minutes")) d = 60000L * Math.max(10, time);
if (unit.equals("hours")) d += 60000L * 60L * time; if (unit.equals("hours")) d = hour * time;
if (unit.equals("days")) d += 60000L * 60L * 24L * time; if (unit.equals("days")) d = day * time;
if (d < System.currentTimeMillis()) d = System.currentTimeMillis() + 600000L; if ((d + date.getTime()) < System.currentTimeMillis()) { // missed schedule
d += System.currentTimeMillis(); // advance next exec from now
} else {
d += date.getTime(); // advance next exec from last execution
}
d -= d % 60000; // remove seconds d -= d % 60000; // remove seconds
} else { } else {
String action = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_ACTION, "startup"); String action = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_ACTION, "startup");

@ -2190,6 +2190,10 @@ public final class Switchboard extends serverSwitch {
} }
} }
/**
* Check scheduled api calls scheduled execution time and execute all jobs due
* @return true if calls have been executed
*/
public boolean schedulerJob() { public boolean schedulerJob() {
// execute scheduled API actions // execute scheduled API actions
@ -2244,16 +2248,6 @@ public final class Switchboard extends serverSwitch {
} catch (final IOException e) { } catch (final IOException e) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
} }
for (final String pk : pks) {
try {
row = this.tables.select(WorkTables.TABLE_API_NAME, UTF8.getBytes(pk));
WorkTables.calculateAPIScheduler(row, true); // calculate next update time
this.tables.update(WorkTables.TABLE_API_NAME, row);
} catch (final Throwable e ) {
ConcurrentLog.logException(e);
continue;
}
}
startupAction = false; startupAction = false;
// execute api calls // execute api calls

Loading…
Cancel
Save