-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Added filevisitor implementation"
This reverts commit 09aa6c6.
- Loading branch information
chris.ditcher
authored and
chris.ditcher
committed
Jul 17, 2023
1 parent
6163c11
commit facad35
Showing
7 changed files
with
35 additions
and
142 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
40 changes: 20 additions & 20 deletions
40
api/src/main/java/ca/bc/gov/educ/api/distribution/config/ScheduledTasksConfig.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 |
---|---|---|
@@ -1,45 +1,45 @@ | ||
package ca.bc.gov.educ.api.distribution.config; | ||
|
||
import ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants; | ||
import ca.bc.gov.educ.api.distribution.util.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitor; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.io.File; | ||
import java.io.FileFilter; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Configuration | ||
public class ScheduledTasksConfig { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ScheduledTasksConfig.class); | ||
|
||
EducDistributionApiConstants educDistributionApiConstants; | ||
FileVisitor<Path> fileVisitor; | ||
FileFilter fileFilter; | ||
|
||
@Autowired | ||
public ScheduledTasksConfig(@Qualifier("TmpCacheFileVisitor") FileVisitor<Path> fileVisitor, EducDistributionApiConstants educDistributionApiConstants) { | ||
this.fileVisitor = fileVisitor; | ||
this.educDistributionApiConstants = educDistributionApiConstants; | ||
public ScheduledTasksConfig(FileFilter fileFilter) { | ||
this.fileFilter = fileFilter; | ||
} | ||
|
||
@Scheduled(cron = "${scheduler.clean-tmp-cache-cron}") | ||
public void cleanTmpCacheFiles() { | ||
Path startingDir = Paths.get(educDistributionApiConstants.getCleanTmpCacheBaseDir()); | ||
if(Files.exists(startingDir)){ | ||
try { | ||
Files.walkFileTree(startingDir, fileVisitor); | ||
} catch (IOException e) { | ||
logger.error("ScheduledTasksConfig: There was an error removing file cache: {}", e.getLocalizedMessage()); | ||
File dir = new File(EducDistributionApiConstants.TMP_DIR); | ||
List<File> files = Arrays.asList(dir.listFiles(this.fileFilter)); | ||
LocalDateTime fileExpiry = LocalDateTime.now().minusHours(3); | ||
files.forEach(file -> { | ||
LocalDateTime lastModified = LocalDateTime.ofInstant(Instant.ofEpochMilli(file.lastModified()), ZoneId.systemDefault()); | ||
if(lastModified.isBefore(fileExpiry)){ | ||
logger.debug("Removing file or directory: {}", file.getName()); | ||
IOUtils.removeFileOrDirectory(file); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
||
} |
74 changes: 0 additions & 74 deletions
74
...src/main/java/ca/bc/gov/educ/api/distribution/util/DeleteExpiredFilesFileVisitorImpl.java
This file was deleted.
Oops, something went wrong.
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
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