Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

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)

reger2910fe35c199
diff --git a/source/net/yacy/data/WorkTables.java b/source/net/yacy/data/WorkTables.java
index b265b848d..b5e746998 100644
--- a/source/net/yacy/data/WorkTables.java
+++ b/source/net/yacy/data/WorkTables.java
@@ -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_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_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_ROBOTS_NAME = "robots";
@@ -146,6 +146,7 @@ public class WorkTables extends Tables {
// insert APICALL attributes
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);
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 = 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;
- long d = date.getTime();
+ long d = 0;
final String kind = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_KIND, "off");
if ("off".equals(kind)) {
- int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, 1);
- if (time <= 0) {
+ int time = row.get(WorkTables.TABLE_API_COL_APICALL_SCHEDULE_TIME, -1);
+ if (time <= 0) { // no schedule time
row.put(WorkTables.TABLE_API_COL_DATE_NEXT_EXEC, "");
return;
}
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("hours")) d += 60000L * 60L * time;
- if (unit.equals("days")) d += 60000L * 60L * 24L * time;
- if (d < System.currentTimeMillis()) d = System.currentTimeMillis() + 600000L;
+ if (unit.equals("minutes")) d = 60000L * Math.max(10, time);
+ if (unit.equals("hours")) d = hour * time;
+ if (unit.equals("days")) d = day * time;
+ 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
} else {
String action = row.get(WorkTables.TABLE_API_COL_APICALL_EVENT_ACTION, "startup");
diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java
index dc3af0bf6..c03b6b1ac 100644
--- a/source/net/yacy/search/Switchboard.java
+++ b/source/net/yacy/search/Switchboard.java
@@ -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() {
// execute scheduled API actions
@@ -2244,16 +2248,6 @@ public final class Switchboard extends serverSwitch {
} catch (final IOException 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;
// execute api calls