Search in sources :

Example 6 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class AcquireTimerJobsCmd method execute.

public AcquiredTimerJobEntities execute(CommandContext commandContext) {
    AcquiredTimerJobEntities acquiredJobs = new AcquiredTimerJobEntities();
    List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findTimerJobsToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));
    for (TimerJobEntity job : timerJobs) {
        lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
        acquiredJobs.addJob(job);
    }
    return acquiredJobs;
}
Also used : Page(org.activiti.engine.impl.Page) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) AcquiredTimerJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)

Example 7 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DefaultJobManager method activateSuspendedJob.

@Override
public AbstractJobEntity activateSuspendedJob(SuspendedJobEntity job) {
    AbstractJobEntity activatedJob = null;
    if (Job.JOB_TYPE_TIMER.equals(job.getJobType())) {
        activatedJob = createTimerJobFromOtherJob(job);
        processEngineConfiguration.getTimerJobEntityManager().insert((TimerJobEntity) activatedJob);
    } else {
        activatedJob = createExecutableJobFromOtherJob(job);
        JobEntity jobEntity = (JobEntity) activatedJob;
        processEngineConfiguration.getJobEntityManager().insert(jobEntity);
        triggerExecutorIfNeeded(jobEntity);
    }
    processEngineConfiguration.getSuspendedJobEntityManager().delete(job);
    return activatedJob;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity)

Example 8 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DefaultJobManager method executeTimerJob.

protected void executeTimerJob(JobEntity timerEntity) {
    TimerJobEntityManager timerJobEntityManager = processEngineConfiguration.getTimerJobEntityManager();
    VariableScope variableScope = null;
    if (timerEntity.getExecutionId() != null) {
        variableScope = getExecutionEntityManager().findById(timerEntity.getExecutionId());
    }
    if (variableScope == null) {
        variableScope = NoExecutionVariableScope.getSharedInstance();
    }
    // set endDate if it was set to the definition
    restoreExtraData(timerEntity, variableScope);
    if (timerEntity.getDuedate() != null && !isValidTime(timerEntity, timerEntity.getDuedate(), variableScope)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Timer {} fired. but the dueDate is after the endDate.  Deleting timer.", timerEntity.getId());
        }
        processEngineConfiguration.getJobEntityManager().delete(timerEntity);
        return;
    }
    executeJobHandler(timerEntity);
    processEngineConfiguration.getJobEntityManager().delete(timerEntity);
    if (logger.isDebugEnabled()) {
        logger.debug("Timer {} fired. Deleting timer.", timerEntity.getId());
    }
    if (timerEntity.getRepeat() != null) {
        TimerJobEntity newTimerJobEntity = timerJobEntityManager.createAndCalculateNextTimer(timerEntity, variableScope);
        if (newTimerJobEntity != null) {
            scheduleTimerJob(newTimerJobEntity);
        }
    }
}
Also used : TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntityManager(org.activiti.engine.impl.persistence.entity.TimerJobEntityManager) VariableScope(org.activiti.engine.delegate.VariableScope) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope)

Example 9 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DefaultJobManager method moveJobToTimerJob.

@Override
public TimerJobEntity moveJobToTimerJob(AbstractJobEntity job) {
    TimerJobEntity timerJob = createTimerJobFromOtherJob(job);
    boolean insertSuccesful = processEngineConfiguration.getTimerJobEntityManager().insertTimerJobEntity(timerJob);
    if (insertSuccesful) {
        if (job instanceof JobEntity) {
            processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
        } else if (job instanceof SuspendedJobEntity) {
            processEngineConfiguration.getSuspendedJobEntityManager().delete((SuspendedJobEntity) job);
        }
        return timerJob;
    }
    return null;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 10 with TimerJobEntity

use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.

the class DefaultJobManager method moveJobToDeadLetterJob.

@Override
public DeadLetterJobEntity moveJobToDeadLetterJob(AbstractJobEntity job) {
    DeadLetterJobEntity deadLetterJob = createDeadLetterJobFromOtherJob(job);
    processEngineConfiguration.getDeadLetterJobEntityManager().insert(deadLetterJob);
    if (job instanceof TimerJobEntity) {
        processEngineConfiguration.getTimerJobEntityManager().delete((TimerJobEntity) job);
    } else if (job instanceof JobEntity) {
        processEngineConfiguration.getJobEntityManager().delete((JobEntity) job);
    }
    return deadLetterJob;
}
Also used : DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) AbstractJobEntity(org.activiti.engine.impl.persistence.entity.AbstractJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) DeadLetterJobEntity(org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)

Aggregations

TimerJobEntity (org.activiti.engine.impl.persistence.entity.TimerJobEntity)28 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)8 SuspendedJobEntity (org.activiti.engine.impl.persistence.entity.SuspendedJobEntity)7 DeadLetterJobEntity (org.activiti.engine.impl.persistence.entity.DeadLetterJobEntity)6 Deployment (org.activiti.engine.test.Deployment)6 AbstractJobEntity (org.activiti.engine.impl.persistence.entity.AbstractJobEntity)5 Job (org.activiti.engine.runtime.Job)5 ActivitiException (org.activiti.engine.ActivitiException)4 JobManager (org.activiti.engine.impl.asyncexecutor.JobManager)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)4 Date (java.util.Date)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 Calendar (java.util.Calendar)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 VariableScope (org.activiti.engine.delegate.VariableScope)2 Page (org.activiti.engine.impl.Page)2 AcquiredTimerJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities)2 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)2 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)2