-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added clean up for deleting all the malicious entries older than 7 days
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/threat-detection/src/main/java/com/akto/threat/detection/tasks/CleanupTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.akto.threat.detection.tasks; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.time.LocalDate; | ||
import java.time.ZoneOffset; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.akto.threat.detection.db.malicious_event.MaliciousEventDao; | ||
|
||
public class CleanupTask implements Task { | ||
|
||
private final MaliciousEventDao maliciousEventDao; | ||
private final ScheduledExecutorService cronExecutorService = Executors.newScheduledThreadPool(1); | ||
|
||
public CleanupTask(Connection conn) { | ||
this.maliciousEventDao = new MaliciousEventDao(conn); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
this.cronExecutorService.scheduleAtFixedRate(this::cleanup, 5, 10 * 60, TimeUnit.SECONDS); | ||
} | ||
|
||
private void cleanup() { | ||
// Delete all records older than 7 days | ||
try { | ||
this.maliciousEventDao.deleteEventsBefore(LocalDate.now(ZoneOffset.UTC).minusDays(7)); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters