Search in sources :

Example 31 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class BatchEntity method createMonitorJob.

public JobEntity createMonitorJob(boolean setDueDate) {
    // Maybe use an other job declaration
    JobEntity monitorJob = BATCH_MONITOR_JOB_DECLARATION.createJobInstance(this);
    if (setDueDate) {
        monitorJob.setDuedate(calculateMonitorJobDueDate());
    }
    Context.getCommandContext().getJobManager().insertAndHintJobExecutor(monitorJob);
    return monitorJob;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity)

Example 32 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class BatchEntity method createSeedJob.

public JobEntity createSeedJob() {
    JobEntity seedJob = BATCH_SEED_JOB_DECLARATION.createJobInstance(this);
    Context.getCommandContext().getJobManager().insertAndHintJobExecutor(seedJob);
    return seedJob;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity)

Example 33 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity 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)

Example 34 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class UnlockJobCmd method execute.

public Void execute(CommandContext commandContext) {
    JobEntity job = getJob();
    if (Context.getJobExecutorContext() == null) {
        EnsureUtil.ensureNotNull("Job with id " + jobId + " does not exist", "job", job);
    } else if (Context.getJobExecutorContext() != null && job == null) {
        // CAM-1842
        // Job was acquired but does not exist anymore. This is not a problem.
        // It usually means that the job has been deleted after it was acquired which can happen if the
        // the activity instance corresponding to the job is cancelled.
        LOG.debugAcquiredJobNotFound(jobId);
        return null;
    }
    job.unlock();
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity)

Example 35 with JobEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.

the class DefaultHistoryEventProducer method initHistoricJobLogEvent.

protected void initHistoricJobLogEvent(HistoricJobLogEventEntity evt, Job job, HistoryEventType eventType) {
    evt.setTimestamp(ClockUtil.getCurrentTime());
    JobEntity jobEntity = (JobEntity) job;
    evt.setJobId(jobEntity.getId());
    evt.setJobDueDate(jobEntity.getDuedate());
    evt.setJobRetries(jobEntity.getRetries());
    evt.setJobPriority(jobEntity.getPriority());
    JobDefinition jobDefinition = jobEntity.getJobDefinition();
    if (jobDefinition != null) {
        evt.setJobDefinitionId(jobDefinition.getId());
        evt.setJobDefinitionType(jobDefinition.getJobType());
        evt.setJobDefinitionConfiguration(jobDefinition.getJobConfiguration());
    } else {
        // in case of async signal there does not exist a job definition
        // but we use the jobHandlerType as jobDefinitionType
        evt.setJobDefinitionType(jobEntity.getJobHandlerType());
    }
    evt.setActivityId(jobEntity.getActivityId());
    evt.setExecutionId(jobEntity.getExecutionId());
    evt.setProcessInstanceId(jobEntity.getProcessInstanceId());
    evt.setProcessDefinitionId(jobEntity.getProcessDefinitionId());
    evt.setProcessDefinitionKey(jobEntity.getProcessDefinitionKey());
    evt.setDeploymentId(jobEntity.getDeploymentId());
    evt.setTenantId(jobEntity.getTenantId());
    // initialize sequence counter
    initSequenceCounter(jobEntity, evt);
    JobState state = null;
    if (HistoryEventTypes.JOB_CREATE.equals(eventType)) {
        state = JobState.CREATED;
    } else if (HistoryEventTypes.JOB_FAIL.equals(eventType)) {
        state = JobState.FAILED;
    } else if (HistoryEventTypes.JOB_SUCCESS.equals(eventType)) {
        state = JobState.SUCCESSFUL;
    } else if (HistoryEventTypes.JOB_DELETE.equals(eventType)) {
        state = JobState.DELETED;
    }
    evt.setState(state.getStateCode());
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) JobState(org.camunda.bpm.engine.history.JobState) JobDefinition(org.camunda.bpm.engine.management.JobDefinition)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3