use of org.lastaflute.job.subsidiary.CronParamsSupplier in project fess by codelibs.
the class JobHelper method register.
public void register(final LaCron cron, final ScheduledJob scheduledJob) {
if (scheduledJob == null) {
throw new ScheduledJobException("No job.");
}
final String id = scheduledJob.getId();
if (!Constants.T.equals(scheduledJob.getAvailable())) {
logger.info("Inactive Job " + id + ":" + scheduledJob.getName());
try {
unregister(scheduledJob);
} catch (final Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to delete Job " + scheduledJob, e);
}
}
return;
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final CronParamsSupplier paramsOp = () -> {
final Map<String, Object> params = new HashMap<>();
params.put(Constants.SCHEDULED_JOB, ComponentUtil.getComponent(ScheduledJobBhv.class).selectByPK(scheduledJob.getId()).orElseThrow(() -> new JobNotFoundException(scheduledJob)));
return params;
};
findJobByUniqueOf(LaJobUnique.of(id)).ifPresent(job -> {
if (!job.isUnscheduled()) {
if (StringUtil.isNotBlank(scheduledJob.getCronExpression())) {
logger.info("Starting Job " + id + ":" + scheduledJob.getName());
final String cronExpression = scheduledJob.getCronExpression();
job.reschedule(cronExpression, op -> op.changeNoticeLogToDebug().params(paramsOp));
} else {
logger.info("Inactive Job " + id + ":" + scheduledJob.getName());
job.becomeNonCron();
}
} else if (StringUtil.isNotBlank(scheduledJob.getCronExpression())) {
logger.info("Starting Job " + id + ":" + scheduledJob.getName());
final String cronExpression = scheduledJob.getCronExpression();
job.reschedule(cronExpression, op -> op.changeNoticeLogToDebug().params(paramsOp));
}
}).orElse(() -> {
if (StringUtil.isNotBlank(scheduledJob.getCronExpression())) {
logger.info("Starting Job " + id + ":" + scheduledJob.getName());
final String cronExpression = scheduledJob.getCronExpression();
cron.register(cronExpression, fessConfig.getSchedulerJobClassAsClass(), fessConfig.getSchedulerConcurrentExecModeAsEnum(), op -> op.uniqueBy(id).changeNoticeLogToDebug().params(paramsOp));
} else {
logger.info("Inactive Job " + id + ":" + scheduledJob.getName());
cron.registerNonCron(fessConfig.getSchedulerJobClassAsClass(), fessConfig.getSchedulerConcurrentExecModeAsEnum(), op -> op.uniqueBy(id).changeNoticeLogToDebug().params(paramsOp));
}
});
}
Aggregations