Search in sources :

Example 1 with JobLogService

use of org.codelibs.fess.app.service.JobLogService in project fess by codelibs.

the class PurgeLogJob method execute.

public String execute() {
    final CrawlingInfoService crawlingInfoService = ComponentUtil.getComponent(CrawlingInfoService.class);
    final SearchLogService searchLogService = ComponentUtil.getComponent(SearchLogService.class);
    final JobLogService jobLogService = ComponentUtil.getComponent(JobLogService.class);
    final UserInfoService userInfoService = ComponentUtil.getComponent(UserInfoService.class);
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    // purge crawling sessions
    try {
        crawlingInfoService.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 int days = ComponentUtil.getFessConfig().getPurgeSearchLogDay();
        if (days >= 0) {
            searchLogService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge search logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge search logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // purge job logs
    try {
        final int days = ComponentUtil.getFessConfig().getPurgeJobLogDay();
        if (days >= 0) {
            jobLogService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge job logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge job logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // purge user info
    try {
        final int days = ComponentUtil.getFessConfig().getPurgeUserInfoDay();
        if (days >= 0) {
            userInfoService.deleteBefore(days);
        } else {
            resultBuf.append("Skipped to purge user info logs.\n");
        }
    } catch (final Exception e) {
        logger.error("Failed to purge user info.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    // update job logs
    try {
        jobLogService.updateStatus();
    } catch (final Exception e) {
        logger.error("Failed to purge job logs.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    return resultBuf.toString();
}
Also used : SearchLogService(org.codelibs.fess.app.service.SearchLogService) SystemHelper(org.codelibs.fess.helper.SystemHelper) JobLogService(org.codelibs.fess.app.service.JobLogService) CrawlingInfoService(org.codelibs.fess.app.service.CrawlingInfoService) UserInfoService(org.codelibs.fess.app.service.UserInfoService)

Aggregations

CrawlingInfoService (org.codelibs.fess.app.service.CrawlingInfoService)1 JobLogService (org.codelibs.fess.app.service.JobLogService)1 SearchLogService (org.codelibs.fess.app.service.SearchLogService)1 UserInfoService (org.codelibs.fess.app.service.UserInfoService)1 SystemHelper (org.codelibs.fess.helper.SystemHelper)1