Search in sources :

Example 1 with HistoryCleanupContext

use of org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupContext in project camunda-bpm-platform by camunda.

the class HistoryCleanupCmd method execute.

@Override
public Job execute(CommandContext commandContext) {
    commandContext.getAuthorizationManager().checkCamundaAdmin();
    // validate
    if (!willBeScheduled(commandContext)) {
        LOG.debugHistoryCleanupWrongConfiguration();
    }
    // find job instance
    JobEntity historyCleanupJob = commandContext.getJobManager().findJobByHandlerType(HistoryCleanupJobHandler.TYPE);
    boolean createJob = historyCleanupJob == null && willBeScheduled(commandContext);
    boolean reconfigureJob = historyCleanupJob != null && willBeScheduled(commandContext);
    boolean suspendJob = historyCleanupJob != null && !willBeScheduled(commandContext);
    if (createJob) {
        // exclusive lock
        commandContext.getPropertyManager().acquireExclusiveLockForHistoryCleanupJob();
        // check again after lock
        historyCleanupJob = commandContext.getJobManager().findJobByHandlerType(HistoryCleanupJobHandler.TYPE);
        if (historyCleanupJob == null) {
            historyCleanupJob = HISTORY_CLEANUP_JOB_DECLARATION.createJobInstance(new HistoryCleanupContext(immediatelyDue));
            Context.getCommandContext().getJobManager().insertAndHintJobExecutor(historyCleanupJob);
        }
    } else if (reconfigureJob) {
        // apply new configuration
        HistoryCleanupContext historyCleanupContext = new HistoryCleanupContext(immediatelyDue);
        HISTORY_CLEANUP_JOB_DECLARATION.reconfigure(historyCleanupContext, historyCleanupJob);
        Date newDueDate = HISTORY_CLEANUP_JOB_DECLARATION.resolveDueDate(historyCleanupContext);
        commandContext.getJobManager().reschedule(historyCleanupJob, newDueDate);
    } else if (suspendJob) {
        historyCleanupJob.setDuedate(null);
        historyCleanupJob.setSuspensionState(SuspensionState.SUSPENDED.getStateCode());
    }
    return historyCleanupJob;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoryCleanupContext(org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupContext) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 HistoryCleanupContext (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupContext)1 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)1