+ public Date getLastExecution() {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? ORDER BY `when` DESC LIMIT 1")) {
+ ps.setInt(1, id);
+ GigiResultSet rs = ps.executeQuery();
+ if (rs.next()) {
+ return new Date(rs.getTimestamp("stamp").getTime());
+ }
+ return new Date(0);
+ }
+ }
+
+ public Date getLastSuccess() {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `when` AS stamp from `domainPinglog` WHERE `configId`=? AND state='success' ORDER BY `when` DESC LIMIT 1")) {
+ ps.setInt(1, id);
+ GigiResultSet rs = ps.executeQuery();
+ if (rs.next()) {
+ return new Date(rs.getTimestamp("stamp").getTime());
+ }
+ return new Date(0);
+ }
+ }
+
+ public synchronized void requestReping() throws GigiApiException {
+ Date lastExecution = getLastExecution();
+ if (lastExecution.getTime() + 5 * 60 * 1000 < System.currentTimeMillis()) {
+ Gigi.notifyPinger(this);
+ return;
+ }
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("data", new Date(lastExecution.getTime() + 5 * 60 * 1000));
+ throw new GigiApiException(new Scope(new SprintfCommand("Reping is only allowed after 5 minutes, yours end at {0}.", Arrays.asList("${data}")), data));
+ }