-
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.
Clean temp folder after completing PDF generation
- Loading branch information
1 parent
f4b6867
commit 25c7473
Showing
5 changed files
with
55 additions
and
9 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
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
44 changes: 44 additions & 0 deletions
44
SimplePdfGenAPI/src/main/java/org/shuhanmirza/simplepdfgenapi/service/PdfCleanUpService.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,44 @@ | ||
package org.shuhanmirza.simplepdfgenapi.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.FileUtils; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Mono; | ||
import reactor.core.scheduler.Schedulers; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author Shuhan Mirza | ||
* @since 17/1/24 | ||
*/ | ||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class PdfCleanUpService { | ||
|
||
private static long DELETE_FOLDER_DELAY_MINUTES = 15L; | ||
|
||
private Mono<Boolean> deleteFolder(String folderPath) { | ||
|
||
var folder = new File(folderPath); | ||
try { | ||
FileUtils.deleteDirectory(folder); | ||
} catch (IOException ioException) { | ||
log.error("Failed to delete {}", folderPath, ioException); | ||
return Mono.just(Boolean.FALSE); | ||
} | ||
|
||
log.info("Deleted {}", folder.getAbsolutePath()); | ||
|
||
return Mono.just(Boolean.TRUE); | ||
} | ||
|
||
public void scheduleFolderForDeletion(String folderPath) { | ||
Schedulers.boundedElastic().schedule(() -> deleteFolder(folderPath).subscribe(), DELETE_FOLDER_DELAY_MINUTES, TimeUnit.MINUTES); | ||
} | ||
|
||
} |
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