mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
REPO-5571 : Add tempFileCleanerTrigger configurations to be able to limit the job duration/quantity
- fixed log order
This commit is contained in:
@@ -441,12 +441,8 @@ public class TempFileProvider
|
||||
|
||||
File tempDir = TempFileProvider.getTempDir(directoryName);
|
||||
int count = removeFiles(tempDir, aFewHoursBack, aLongTimeBack, false); // don't delete this directory
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Removed " + count + " files from temp directory: " + tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all temporary files created before the given time.
|
||||
@@ -485,26 +481,20 @@ public class TempFileProvider
|
||||
int count = 0;
|
||||
for (File file : filesToIterate)
|
||||
{
|
||||
if (shouldTheDeletionStop())
|
||||
{
|
||||
logger.debug("Stopping, limit has been reached.");
|
||||
break;
|
||||
}
|
||||
if (file.isDirectory())
|
||||
{
|
||||
if(isLongLifeTempDir(file))
|
||||
{
|
||||
// long life for this folder and its children
|
||||
int countRemoved = removeFiles(file, longLifeBefore, longLifeBefore, true);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Removed " + countRemoved + " files from temp directory: " + file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// OR
|
||||
// enter subdirectory and clean it out and remove itsynetics
|
||||
int countRemoved = removeFiles(file, removeBefore, longLifeBefore, true);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Removed " + countRemoved + " files from directory: " + file);
|
||||
}
|
||||
}
|
||||
int countRemoved = removeFiles(file,
|
||||
isLongLifeTempDir(file) ? longLifeBefore : removeBefore, longLifeBefore,
|
||||
true);
|
||||
logger.debug("Removed " + countRemoved + " files from " + (isLongLifeTempDir(file) ? "temp " : " ") + "directory: " + file);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -516,34 +506,20 @@ public class TempFileProvider
|
||||
}
|
||||
// it is a file - attempt a delete
|
||||
try
|
||||
{
|
||||
// only delete if the limits allow
|
||||
if (maxFilesToDelete != null && maxFilesToDelete.get() <= 0 ||
|
||||
maxTimeToRun != null && ((jobStartTime + maxTimeToRun.toMillis()) < System.currentTimeMillis()))
|
||||
{
|
||||
return count;
|
||||
}
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Deleting temp file: " + file);
|
||||
}
|
||||
file.delete();
|
||||
|
||||
if (maxFilesToDelete != null)
|
||||
{
|
||||
maxFilesToDelete.decrementAndGet();
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
if (maxFilesToDelete != null)
|
||||
{
|
||||
logger.debug(maxFilesToDelete.get() + " files left to delete.");
|
||||
}
|
||||
if (maxTimeToRun != null)
|
||||
{
|
||||
logger.debug((jobStartTime + maxTimeToRun.toMillis() - System.currentTimeMillis()) + " millis left to delete.");
|
||||
}
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
catch (Throwable e)
|
||||
@@ -562,10 +538,7 @@ public class TempFileProvider
|
||||
if(listing != null && listing.length == 0)
|
||||
{
|
||||
// directory is empty
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Deleting empty directory: " + directory);
|
||||
}
|
||||
// ignore the limits for empty directories that just need cleanup
|
||||
directory.delete();
|
||||
}
|
||||
@@ -575,8 +548,21 @@ public class TempFileProvider
|
||||
logger.info("Failed to remove temp directory: " + directory, e);
|
||||
}
|
||||
}
|
||||
// done
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether or not the job should continue iterating through the temp files and delete.
|
||||
* It achieves the result by checking the number of files deleted against the limit and whether
|
||||
* or not it is within the time limit
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
private static boolean shouldTheDeletionStop()
|
||||
{
|
||||
return maxFilesToDelete != null && maxFilesToDelete.get() <= 0
|
||||
|| maxTimeToRun != null && ((jobStartTime + maxTimeToRun.toMillis()) < System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user