-
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.
Merge branch 'main' into grad-release
- Loading branch information
Showing
10 changed files
with
43 additions
and
288 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
43 changes: 20 additions & 23 deletions
43
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,48 +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; | ||
} | ||
|
||
/** | ||
* Removes artifacts from the /tmp directory that are expired | ||
*/ | ||
@Scheduled(cron = "${scheduler.clean-tmp-cache-cron}") | ||
public void cleanTmpCacheFiles() { | ||
logger.debug("Running clean cache..."); | ||
Path startingDir = Paths.get(educDistributionApiConstants.TMP_DIR); | ||
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); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
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
66 changes: 0 additions & 66 deletions
66
...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
Oops, something went wrong.