fix #1617 add cleanup option
This commit is contained in:
parent
12c07bd508
commit
cf20a1a84f
3 changed files with 53 additions and 30 deletions
|
@ -64,6 +64,9 @@ public class ThumbnailGenerator {
|
|||
@Option(name = "-t", aliases = "--numOfThreads", metaVar = "numOfThreads", usage = "The number of threads")
|
||||
protected int numOfThreads = 1;
|
||||
|
||||
@Option(name = "-c", aliases = "--cleanup", usage = "Clean-Up mode")
|
||||
protected boolean cleanup;
|
||||
|
||||
protected Options() {
|
||||
// nothing
|
||||
}
|
||||
|
@ -194,7 +197,7 @@ public class ThumbnailGenerator {
|
|||
int count = 1;
|
||||
final ForkJoinPool pool = new ForkJoinPool(options.numOfThreads);
|
||||
while (count != 0) {
|
||||
count = ComponentUtil.getThumbnailManager().generate(pool);
|
||||
count = ComponentUtil.getThumbnailManager().generate(pool, options.cleanup);
|
||||
totalCount += count;
|
||||
}
|
||||
return totalCount;
|
||||
|
|
|
@ -57,6 +57,8 @@ public class GenerateThumbnailJob {
|
|||
|
||||
protected int numOfThreads = 1;
|
||||
|
||||
protected boolean cleanup = false;
|
||||
|
||||
protected String logLevel;
|
||||
|
||||
protected String jvmOptions;
|
||||
|
@ -83,6 +85,11 @@ public class GenerateThumbnailJob {
|
|||
return this;
|
||||
}
|
||||
|
||||
public GenerateThumbnailJob cleanup() {
|
||||
this.cleanup = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GenerateThumbnailJob logLevel(final String logLevel) {
|
||||
this.logLevel = logLevel;
|
||||
return this;
|
||||
|
@ -246,6 +253,9 @@ public class GenerateThumbnailJob {
|
|||
cmdList.add(sessionId);
|
||||
cmdList.add("--numOfThreads");
|
||||
cmdList.add(Integer.toString(numOfThreads));
|
||||
if (cleanup) {
|
||||
cmdList.add("--cleanup");
|
||||
}
|
||||
|
||||
File propFile = null;
|
||||
try {
|
||||
|
|
|
@ -189,7 +189,7 @@ public class ThumbnailManager {
|
|||
thumbnailQueueBhv.batchInsert(list);
|
||||
}
|
||||
|
||||
public int generate(final ForkJoinPool pool) {
|
||||
public int generate(final ForkJoinPool pool, final boolean cleanup) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final List<String> idList = new ArrayList<>();
|
||||
final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
|
||||
|
@ -202,36 +202,13 @@ public class ThumbnailManager {
|
|||
cb.query().addOrderBy_CreatedTime_Asc();
|
||||
cb.fetchFirst(fessConfig.getPageThumbnailQueueMaxFetchSizeAsInteger());
|
||||
}).parallelStream().forEach(entity -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Generating thumbnail: " + entity);
|
||||
}
|
||||
idList.add(entity.getId());
|
||||
final String generatorName = entity.getGenerator();
|
||||
try {
|
||||
final File outputFile = new File(baseDir, entity.getPath());
|
||||
final File noImageFile = new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX);
|
||||
if (!noImageFile.isFile() || System.currentTimeMillis() - noImageFile.lastModified() > noImageExpired) {
|
||||
if (noImageFile.isFile() && !noImageFile.delete()) {
|
||||
logger.warn("Failed to delete " + noImageFile.getAbsolutePath());
|
||||
}
|
||||
final ThumbnailGenerator generator = ComponentUtil.getComponent(generatorName);
|
||||
if (generator.isAvailable()) {
|
||||
if (!generator.generate(entity.getThumbnailId(), outputFile)) {
|
||||
new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX).setLastModified(System.currentTimeMillis());
|
||||
} else {
|
||||
final long interval = fessConfig.getThumbnailGeneratorIntervalAsInteger().longValue();
|
||||
if (interval > 0) {
|
||||
Thread.sleep(interval);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn(generatorName + " is not available.");
|
||||
}
|
||||
} else if (logger.isDebugEnabled()) {
|
||||
logger.debug("No image file exists: " + noImageFile.getAbsolutePath());
|
||||
if (cleanup) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Removing thumbnail queue: " + entity);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create thumbnail for " + entity, e);
|
||||
} else {
|
||||
process(fessConfig, entity);
|
||||
}
|
||||
})).join();
|
||||
if (!idList.isEmpty()) {
|
||||
|
@ -243,6 +220,39 @@ public class ThumbnailManager {
|
|||
return idList.size();
|
||||
}
|
||||
|
||||
protected void process(final FessConfig fessConfig, ThumbnailQueue entity) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Processing thumbnail: " + entity);
|
||||
}
|
||||
final String generatorName = entity.getGenerator();
|
||||
try {
|
||||
final File outputFile = new File(baseDir, entity.getPath());
|
||||
final File noImageFile = new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX);
|
||||
if (!noImageFile.isFile() || System.currentTimeMillis() - noImageFile.lastModified() > noImageExpired) {
|
||||
if (noImageFile.isFile() && !noImageFile.delete()) {
|
||||
logger.warn("Failed to delete " + noImageFile.getAbsolutePath());
|
||||
}
|
||||
final ThumbnailGenerator generator = ComponentUtil.getComponent(generatorName);
|
||||
if (generator.isAvailable()) {
|
||||
if (!generator.generate(entity.getThumbnailId(), outputFile)) {
|
||||
new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX).setLastModified(System.currentTimeMillis());
|
||||
} else {
|
||||
final long interval = fessConfig.getThumbnailGeneratorIntervalAsInteger().longValue();
|
||||
if (interval > 0) {
|
||||
Thread.sleep(interval);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn(generatorName + " is not available.");
|
||||
}
|
||||
} else if (logger.isDebugEnabled()) {
|
||||
logger.debug("No image file exists: " + noImageFile.getAbsolutePath());
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create thumbnail for " + entity, e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean offer(final Map<String, Object> docMap) {
|
||||
for (final ThumbnailGenerator generator : generatorList) {
|
||||
if (generator.isTarget(docMap)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue