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,11 +441,7 @@ public class TempFileProvider
|
|||||||
|
|
||||||
File tempDir = TempFileProvider.getTempDir(directoryName);
|
File tempDir = TempFileProvider.getTempDir(directoryName);
|
||||||
int count = removeFiles(tempDir, aFewHoursBack, aLongTimeBack, false); // don't delete this directory
|
int count = removeFiles(tempDir, aFewHoursBack, aLongTimeBack, false); // don't delete this directory
|
||||||
// done
|
logger.debug("Removed " + count + " files from temp directory: " + tempDir);
|
||||||
if (logger.isDebugEnabled())
|
|
||||||
{
|
|
||||||
logger.debug("Removed " + count + " files from temp directory: " + tempDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -485,26 +481,20 @@ public class TempFileProvider
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (File file : filesToIterate)
|
for (File file : filesToIterate)
|
||||||
{
|
{
|
||||||
|
if (shouldTheDeletionStop())
|
||||||
|
{
|
||||||
|
logger.debug("Stopping, limit has been reached.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (file.isDirectory())
|
if (file.isDirectory())
|
||||||
{
|
{
|
||||||
if(isLongLifeTempDir(file))
|
// long life for this folder and its children
|
||||||
{
|
// OR
|
||||||
// long life for this folder and its children
|
// enter subdirectory and clean it out and remove itsynetics
|
||||||
int countRemoved = removeFiles(file, longLifeBefore, longLifeBefore, true);
|
int countRemoved = removeFiles(file,
|
||||||
if (logger.isDebugEnabled())
|
isLongLifeTempDir(file) ? longLifeBefore : removeBefore, longLifeBefore,
|
||||||
{
|
true);
|
||||||
logger.debug("Removed " + countRemoved + " files from temp directory: " + file);
|
logger.debug("Removed " + countRemoved + " files from " + (isLongLifeTempDir(file) ? "temp " : " ") + "directory: " + file);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -517,33 +507,19 @@ public class TempFileProvider
|
|||||||
// it is a file - attempt a delete
|
// it is a file - attempt a delete
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// only delete if the limits allow
|
logger.debug("Deleting temp file: " + file);
|
||||||
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();
|
file.delete();
|
||||||
|
|
||||||
if (maxFilesToDelete != null)
|
if (maxFilesToDelete != null)
|
||||||
{
|
{
|
||||||
maxFilesToDelete.decrementAndGet();
|
maxFilesToDelete.decrementAndGet();
|
||||||
|
logger.debug(maxFilesToDelete.get() + " files left to delete.");
|
||||||
|
}
|
||||||
|
if (maxTimeToRun != null)
|
||||||
|
{
|
||||||
|
logger.debug((jobStartTime + maxTimeToRun.toMillis() - System.currentTimeMillis()) + " millis left to delete.");
|
||||||
}
|
}
|
||||||
|
|
||||||
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++;
|
count++;
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
@@ -562,10 +538,7 @@ public class TempFileProvider
|
|||||||
if(listing != null && listing.length == 0)
|
if(listing != null && listing.length == 0)
|
||||||
{
|
{
|
||||||
// directory is empty
|
// directory is empty
|
||||||
if(logger.isDebugEnabled())
|
logger.debug("Deleting empty directory: " + directory);
|
||||||
{
|
|
||||||
logger.debug("Deleting empty directory: " + directory);
|
|
||||||
}
|
|
||||||
// ignore the limits for empty directories that just need cleanup
|
// ignore the limits for empty directories that just need cleanup
|
||||||
directory.delete();
|
directory.delete();
|
||||||
}
|
}
|
||||||
@@ -575,8 +548,21 @@ public class TempFileProvider
|
|||||||
logger.info("Failed to remove temp directory: " + directory, e);
|
logger.info("Failed to remove temp directory: " + directory, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// done
|
|
||||||
return count;
|
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