Search in sources :

Example 1 with JobManager

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

the class ManagementServiceTest method createJob.

protected void createJob(final int retries, final String owner, final Date lockExpirationTime) {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobHandlerType("any");
            job.setLockOwner(owner);
            job.setLockExpirationTime(lockExpirationTime);
            job.setRetries(retries);
            jobManager.send(job);
            return null;
        }
    });
}
Also used : MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 2 with JobManager

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

the class JobQueryTest method createJobWithoutExceptionMsg.

private void createJobWithoutExceptionMsg() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            timerEntity = new TimerEntity();
            timerEntity.setLockOwner(UUID.randomUUID().toString());
            timerEntity.setDuedate(new Date());
            timerEntity.setRetries(0);
            StringWriter stringWriter = new StringWriter();
            NullPointerException exception = new NullPointerException();
            exception.printStackTrace(new PrintWriter(stringWriter));
            timerEntity.setExceptionStacktrace(stringWriter.toString());
            jobManager.insert(timerEntity);
            assertNotNull(timerEntity.getId());
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) StringWriter(java.io.StringWriter) TimerEntity(org.camunda.bpm.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 3 with JobManager

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

the class JobQueryTest method createJobWithoutExceptionStacktrace.

private void createJobWithoutExceptionStacktrace() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            timerEntity = new TimerEntity();
            timerEntity.setLockOwner(UUID.randomUUID().toString());
            timerEntity.setDuedate(new Date());
            timerEntity.setRetries(0);
            timerEntity.setExceptionMessage("I'm supposed to fail");
            jobManager.insert(timerEntity);
            assertNotNull(timerEntity.getId());
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) TimerEntity(org.camunda.bpm.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Date(java.util.Date)

Example 4 with JobManager

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

the class DeleteProcessInstancesJobHandler method createJobEntities.

protected void createJobEntities(BatchEntity batch, DeleteProcessInstanceBatchConfiguration configuration, String deploymentId, List<String> processInstancesToHandle, int invocationsPerBatchJob) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    int createdJobs = 0;
    while (!processInstancesToHandle.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processInstancesToHandle.size());
        // view of process instances for this job
        List<String> idsForJob = processInstancesToHandle.subList(0, lastIdIndex);
        DeleteProcessInstanceBatchConfiguration jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        job.setDeploymentId(deploymentId);
        jobManager.insertAndHintJobExecutor(job);
        createdJobs++;
        idsForJob.clear();
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 5 with JobManager

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

the class AbstractBatchJobHandler method createJobs.

@Override
public boolean createJobs(BatchEntity batch) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    T configuration = readConfiguration(batch.getConfigurationBytes());
    int batchJobsPerSeed = batch.getBatchJobsPerSeed();
    int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
    List<String> ids = configuration.getIds();
    int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
    // view of process instances to process
    List<String> processIds = ids.subList(0, numberOfItemsToProcess);
    int createdJobs = 0;
    while (!processIds.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processIds.size());
        // view of process instances for this job
        List<String> idsForJob = processIds.subList(0, lastIdIndex);
        T jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        postProcessJob(configuration, job);
        jobManager.insertAndHintJobExecutor(job);
        idsForJob.clear();
        createdJobs++;
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
    return ids.isEmpty();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Aggregations

JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)10 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)8 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)4 Date (java.util.Date)3 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)2 ByteArrayManager (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager)2 JobDefinitionManager (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)2 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)2 TimerEntity (org.camunda.bpm.engine.impl.persistence.entity.TimerEntity)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 HistoricJobLog (org.camunda.bpm.engine.history.HistoricJobLog)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1