update lasta-job
This commit is contained in:
parent
3df3aa7886
commit
fdc3982085
4 changed files with 33 additions and 52 deletions
4
pom.xml
4
pom.xml
|
@ -41,9 +41,9 @@
|
|||
|
||||
<!-- Main Framework -->
|
||||
<dbflute.version>1.1.1</dbflute.version>
|
||||
<lastaflute.version>0.7.9-RC2</lastaflute.version>
|
||||
<lastaflute.version>0.7.9-RC4</lastaflute.version>
|
||||
<lasta.taglib.version>0.6.8</lasta.taglib.version>
|
||||
<lasta.job.version>0.2.0-RCB</lasta.job.version>
|
||||
<lasta.job.version>0.2.0-RCC</lasta.job.version>
|
||||
<servlet.version>3.1.0</servlet.version>
|
||||
<jsp.version>2.3.1</jsp.version>
|
||||
<mailflute.version>0.4.8</mailflute.version>
|
||||
|
|
|
@ -76,6 +76,8 @@ public class Constants extends CoreLibConstants {
|
|||
|
||||
public static final String DEFAULT_HOURLY_CRON_EXPRESSION = "0 * * * *";
|
||||
|
||||
public static final String UNSCHEDULE_CRON_EXPRESSION = "0 0 1 1 sun";
|
||||
|
||||
public static final int DEFAULT_INTERVAL_TIME_FOR_FS = 1000;
|
||||
|
||||
public static final int DEFAULT_INTERVAL_TIME_FOR_WEB = 30000;
|
||||
|
|
|
@ -27,18 +27,12 @@ import org.codelibs.fess.mylasta.direction.FessConfig;
|
|||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.core.time.TimeManager;
|
||||
import org.lastaflute.di.core.exception.TooManyRegistrationComponentException;
|
||||
import org.lastaflute.di.core.smart.hot.HotdeployUtil;
|
||||
import org.lastaflute.job.LaCron;
|
||||
import org.lastaflute.job.LaJob;
|
||||
import org.lastaflute.job.LaJobRunner;
|
||||
import org.lastaflute.job.LaJobRuntime;
|
||||
import org.lastaflute.job.LaJobScheduler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AllJobScheduler implements LaJobScheduler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AllJobScheduler.class);
|
||||
|
||||
protected static final String APP_TYPE = "JOB";
|
||||
|
||||
|
@ -75,25 +69,7 @@ public class AllJobScheduler implements LaJobScheduler {
|
|||
|
||||
@Override
|
||||
public LaJobRunner createRunner() {
|
||||
return new LaJobRunner() {
|
||||
@Override
|
||||
protected boolean isSuppressHotdeploy() { // TODO workaround
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actuallyRun(Class<? extends LaJob> jobType, LaJobRuntime runtime) { // TODO workaround
|
||||
try {
|
||||
super.actuallyRun(jobType, runtime);
|
||||
} catch (TooManyRegistrationComponentException e) {
|
||||
if (HotdeployUtil.isHotdeploy()) {
|
||||
logger.warn("Failed to start job {}", jobType);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}.useAccessContext(resource -> {
|
||||
return new LaJobRunner().useAccessContext(resource -> {
|
||||
return accessContextLogic.create(resource, () -> OptionalThing.empty(), () -> OptionalThing.empty(), () -> APP_TYPE);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.lastaflute.job.JobManager;
|
|||
import org.lastaflute.job.LaCron;
|
||||
import org.lastaflute.job.LaScheduledJob;
|
||||
import org.lastaflute.job.key.LaJobUnique;
|
||||
import org.lastaflute.job.subsidiary.CronOpCall;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -142,32 +143,26 @@ public class ScheduledJobService implements Serializable {
|
|||
return;
|
||||
}
|
||||
|
||||
final String cronExpression;
|
||||
if (StringUtil.isNotBlank(scheduledJob.getCronExpression())) {
|
||||
logger.info("Starting Job " + id + ":" + scheduledJob.getName());
|
||||
findJobByUniqueOf(LaJobUnique.of(id)).ifPresent(job -> {
|
||||
job.reschedule(scheduledJob.getCronExpression(), option -> option.uniqueBy(id).changeNoticeLogToDebug().params(() -> {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(Constants.SCHEDULED_JOB, scheduledJob);
|
||||
return params;
|
||||
}));
|
||||
}).orElse(
|
||||
() -> {
|
||||
cron.register(scheduledJob.getCronExpression(), fessConfig.getSchedulerJobClassAsClass(),
|
||||
fessConfig.getSchedulerConcurrentExecModeAsEnum(), option -> option.uniqueBy(id).changeNoticeLogToDebug()
|
||||
.params(() -> {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(Constants.SCHEDULED_JOB, scheduledJob);
|
||||
return params;
|
||||
}));
|
||||
});
|
||||
cronExpression = scheduledJob.getCronExpression();
|
||||
} else {
|
||||
logger.info("Inactive Job " + id + ":" + scheduledJob.getName());
|
||||
try {
|
||||
unregister(scheduledJob);
|
||||
} catch (final Exception e) {
|
||||
logger.debug("Failed to delete Job " + scheduledJob, e);
|
||||
}
|
||||
cronExpression = Constants.UNSCHEDULE_CRON_EXPRESSION;
|
||||
}
|
||||
final CronOpCall opLambda = option -> option.uniqueBy(id).changeNoticeLogToDebug().params(() -> {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(Constants.SCHEDULED_JOB, scheduledJob);
|
||||
return params;
|
||||
});
|
||||
findJobByUniqueOf(LaJobUnique.of(id)).ifPresent(job -> {
|
||||
job.reschedule(cronExpression, opLambda);
|
||||
}).orElse(
|
||||
() -> {
|
||||
cron.register(cronExpression, fessConfig.getSchedulerJobClassAsClass(),
|
||||
fessConfig.getSchedulerConcurrentExecModeAsEnum(), opLambda);
|
||||
});
|
||||
}
|
||||
|
||||
private OptionalThing<LaScheduledJob> findJobByUniqueOf(LaJobUnique jobUnique) {
|
||||
|
@ -182,9 +177,11 @@ public class ScheduledJobService implements Serializable {
|
|||
public void unregister(final ScheduledJob scheduledJob) {
|
||||
try {
|
||||
JobManager jobManager = ComponentUtil.getJobManager();
|
||||
jobManager.findJobByUniqueOf(LaJobUnique.of(scheduledJob.getId())).ifPresent(job -> {
|
||||
job.unschedule();
|
||||
}).orElse(() -> logger.debug("Job {} is not scheduled.", scheduledJob.getId()));
|
||||
if (jobManager.isSchedulingDone()) {
|
||||
jobManager.findJobByUniqueOf(LaJobUnique.of(scheduledJob.getId())).ifPresent(job -> {
|
||||
job.unschedule();
|
||||
}).orElse(() -> logger.debug("Job {} is not scheduled.", scheduledJob.getId()));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
throw new ScheduledJobException("Failed to delete Job: " + scheduledJob, e);
|
||||
}
|
||||
|
@ -217,6 +214,12 @@ public class ScheduledJobService implements Serializable {
|
|||
cb.query().setAvailable_Equal(Constants.T);
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
cb.query().addOrderBy_Name_Asc();
|
||||
}, scheduledJob -> register(cron, scheduledJob));
|
||||
}, scheduledJob -> {
|
||||
try {
|
||||
register(cron, scheduledJob);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to start Job " + scheduledJob.getId(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue