This should fix the CMEs

This commit is contained in:
NovaFox161
2017-11-23 10:13:31 -06:00
parent 1379d4f3a1
commit 258ab70369
@@ -8,6 +8,7 @@ import com.cloudcraftgaming.discal.bot.internal.calendar.calendar.CalendarCreato
import com.cloudcraftgaming.discal.bot.internal.calendar.event.EventCreator;
import com.cloudcraftgaming.discal.bot.module.announcement.AnnouncementCreator;
import java.util.ArrayList;
import java.util.TimerTask;
/**
@@ -22,13 +23,17 @@ public class CreatorCleaner extends TimerTask {
try {
long target = 60 * 1000 * 60; //60 minutes
ArrayList<PreCalendar> cals = new ArrayList<>();
ArrayList<PreEvent> events = new ArrayList<>();
ArrayList<Announcement> ans = new ArrayList<>();
//Run through calendar creator
for (PreCalendar cal : CalendarCreator.getCreator().getAllPreCalendars()) {
long difference = System.currentTimeMillis() - cal.getLastEdit();
if (difference <= target) {
//Last edited 60+ minutes ago, delete from creator and free up RAM.
CalendarCreator.getCreator().terminate(cal.getGuildId());
cals.add(cal);
}
}
@@ -38,7 +43,7 @@ public class CreatorCleaner extends TimerTask {
if (difference <= target) {
//Last edited 60+ minutes ago, delete from creator and free up RAM.
EventCreator.getCreator().terminate(event.getGuildId());
events.add(event);
}
}
@@ -48,9 +53,20 @@ public class CreatorCleaner extends TimerTask {
if (difference <= target) {
//Last edited 60+ minutes ago, delete from creator and free up RAM.
AnnouncementCreator.getCreator().terminate(an.getGuildId());
ans.add(an);
}
}
//Okay, actually go through it all and delete
for (PreCalendar c : cals) {
CalendarCreator.getCreator().terminate(c.getGuildId());
}
for (PreEvent e : events) {
EventCreator.getCreator().terminate(e.getGuildId());
}
for (Announcement a : ans) {
AnnouncementCreator.getCreator().terminate(a.getGuildId());
}
} catch (Exception e) {
ExceptionHandler.sendException(null, "Error in CreatorCleaner", e, this.getClass());
}