add PurgeLogJob

This commit is contained in:
Shinsuke Sugaya 2015-11-25 23:02:09 +09:00
parent c1acd18017
commit f25bae59fd
5 changed files with 142 additions and 1 deletions

View file

@ -39,7 +39,7 @@
<!-- Main Framework -->
<dbflute.version>1.1.0-sp8</dbflute.version>
<lastaflute.version>0.6.7-B-SNAPSHOT</lastaflute.version>
<lastaflute.version>0.6.7-RC1</lastaflute.version>
<lasta.taglib.version>0.6.1</lasta.taglib.version>
<servlet.version>3.1.0</servlet.version>
<jsp.version>2.3.1</jsp.version>

View file

@ -0,0 +1,33 @@
package org.codelibs.fess.app.service;
import javax.annotation.Resource;
import org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv;
import org.codelibs.fess.es.log.exbhv.SearchLogBhv;
import org.codelibs.fess.helper.SystemHelper;
public class SearchLogService {
@Resource
private SearchLogBhv searchLogBhv;
@Resource
private SearchFieldLogBhv searchFieldLogBhv;
@Resource
private SystemHelper systemHelper;
public void deleteBefore(int days) {
searchLogBhv.selectCursor(cb -> {
cb.query().setRequestedAt_LessEqual(systemHelper.getCurrentTimeAsLocalDateTime().minusDays(days));
}, entity -> {
searchFieldLogBhv.queryDelete(subCb -> {
subCb.query().setSearchLogId_Equal(entity.getId());
});
});
searchLogBhv.queryDelete(cb -> {
cb.query().setRequestedAt_LessEqual(systemHelper.getCurrentTimeAsLocalDateTime().minusDays(days));
});
}
}

View file

@ -0,0 +1,22 @@
package org.codelibs.fess.app.service;
import javax.annotation.Resource;
import org.codelibs.fess.es.log.exbhv.UserInfoBhv;
import org.codelibs.fess.helper.SystemHelper;
public class UserInfoService {
@Resource
private UserInfoBhv userInfoBhv;
@Resource
private SystemHelper systemHelper;
public void deleteBefore(int days) {
userInfoBhv.queryDelete(cb -> {
cb.query().setUpdatedAt_LessEqual(systemHelper.getCurrentTimeAsLocalDateTime().minusDays(days));
});
}
}

View file

@ -0,0 +1,84 @@
/*
* Copyright 2012-2015 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.job;
import org.codelibs.core.misc.DynamicProperties;
import org.codelibs.fess.Constants;
import org.codelibs.fess.app.service.CrawlingSessionService;
import org.codelibs.fess.app.service.JobLogService;
import org.codelibs.fess.app.service.SearchLogService;
import org.codelibs.fess.app.service.UserInfoService;
import org.codelibs.fess.helper.SystemHelper;
import org.codelibs.fess.util.ComponentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PurgeLogJob {
private static final Logger logger = LoggerFactory.getLogger(PurgeLogJob.class);
public String execute() {
final CrawlingSessionService crawlingSessionService = ComponentUtil.getComponent(CrawlingSessionService.class);
final SearchLogService searchLogService = ComponentUtil.getComponent(SearchLogService.class);
final JobLogService jobLogService = ComponentUtil.getComponent(JobLogService.class);
final UserInfoService userInfoService = ComponentUtil.getComponent(UserInfoService.class);
final DynamicProperties crawlerProperties = ComponentUtil.getCrawlerProperties();
SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final StringBuilder resultBuf = new StringBuilder();
// purge crawling sessions
try {
crawlingSessionService.deleteBefore(systemHelper.getCurrentTimeAsLong());
} catch (final Exception e) {
logger.error("Failed to purge crawling sessions.", e);
resultBuf.append(e.getMessage()).append("\n");
}
// purge search logs
try {
final String value = crawlerProperties.getProperty(Constants.PURGE_SEARCH_LOG_DAY_PROPERTY, Constants.DEFAULT_PURGE_DAY);
final int days = Integer.parseInt(value);
searchLogService.deleteBefore(days);
} catch (final Exception e) {
logger.error("Failed to purge search logs.", e);
resultBuf.append(e.getMessage()).append("\n");
}
// purge job logs
try {
final String value = crawlerProperties.getProperty(Constants.PURGE_JOB_LOG_DAY_PROPERTY, Constants.DEFAULT_PURGE_DAY);
final int days = Integer.parseInt(value);
jobLogService.deleteBefore(days);
} catch (final Exception e) {
logger.error("Failed to purge job logs.", e);
resultBuf.append(e.getMessage()).append("\n");
}
// purge user info
try {
final String value = crawlerProperties.getProperty(Constants.PURGE_USER_INFO_DAY_PROPERTY, Constants.DEFAULT_PURGE_DAY);
final int days = Integer.parseInt(value);
userInfoService.deleteBefore(days);
} catch (final Exception e) {
logger.error("Failed to purge user info.", e);
resultBuf.append(e.getMessage()).append("\n");
}
return resultBuf.toString();
}
}

View file

@ -18,4 +18,6 @@
</component>
<component name="purgeDocJob" class="org.codelibs.fess.job.PurgeDocJob" instance="prototype">
</component>
<component name="purgeLogJob" class="org.codelibs.fess.job.PurgeLogJob" instance="prototype">
</component>
</components>