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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations