Package org.camunda.bpm.engine.impl.persistence.entity

Examples of org.camunda.bpm.engine.impl.persistence.entity.JobEntity


    // when the job retries are reset
    managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);

    // then the job can be picked up again
    JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
    assertNotNull(job);
    assertNull(job.getLockOwner());
    assertNull(job.getLockExpirationTime());
    assertEquals(3, job.getRetries());

    deleteJobAndIncidents(job);
  }
View Full Code Here


    Job remainingJob = managementService.createJobQuery().singleResult();
    assertEquals(currentJobs.get(1).getRetries(), remainingJob.getRetries());

    assertNotNull(remainingJob.getExceptionMessage());

    JobEntity jobEntity = (JobEntity) remainingJob;
    assertNull(jobEntity.getLockOwner());

    // and there is no lock expiration time due to the default retry strategy
    assertNull(jobEntity.getLockExpirationTime());
  }
View Full Code Here

    // retries are configured as R5/PT5M, so no decrement means 5 retries left
    assertEquals(5, remainingJob.getRetries());

    assertNotNull(remainingJob.getExceptionMessage());

    JobEntity jobEntity = (JobEntity) remainingJob;
    assertNull(jobEntity.getLockOwner());

    // and there is a custom lock expiration time
    assertNotNull(jobEntity.getLockExpirationTime());
  }
View Full Code Here

    this.jobIds = new ArrayList<String>();
    jobIds.add(jobId);
  }

  public Void execute(CommandContext commandContext) {
    JobEntity jobToDelete = null;
    for (String jobId: jobIds) {
      jobToDelete = Context
        .getCommandContext()
        .getJobManager()
        .findJobById(jobId);
     
      if(jobToDelete != null) {
        // When given job doesn't exist, ignore
        jobToDelete.delete();
      }
    }
    return null;
  }
View Full Code Here

    this.jobId = jobId;
    this.exception = exception;
  }

  public Object execute(CommandContext commandContext) {
    JobEntity job = Context
      .getCommandContext()
      .getJobManager()
      .findJobById(jobId);
    job.setLockOwner(null);
    job.setLockExpirationTime(null);

    if(exception != null) {
      job.setExceptionMessage(exception.getMessage());
      job.setExceptionStacktrace(getExceptionStacktrace());
    }

    if (exception == null || shouldDecrementRetriesFor(exception)) {
      job.setRetries(job.getRetries() - 1);
    }

    JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor();
    MessageAddedNotification messageAddedNotification = new MessageAddedNotification(jobExecutor);
    TransactionContext transactionContext = commandContext.getTransactionContext();
View Full Code Here

    ensureNotNull("jobId", jobId);
    if (log.isLoggable(Level.FINE)) {
      log.fine("Deleting job " + jobId);
    }

    JobEntity job = commandContext.getJobManager().findJobById(jobId);
    ensureNotNull("No job found with id '" + jobId + "'", "job", job);

    // We need to check if the job was locked, ie acquired by the job acquisition thread
    // This happens if the the job was already acquired, but not yet executed.
    // In that case, we can't allow to delete the job.
    if (job.getLockOwner() != null || job.getLockExpirationTime() != null) {
      throw new ProcessEngineException("Cannot delete job when the job is being executed. Try again later.");
    }

    job.delete();
    return null;
  }
View Full Code Here

    return null;
  }

  protected void setJobRetriesByJobId(CommandContext commandContext) {
    JobEntity job = commandContext
        .getJobManager()
        .findJobById(jobId);
    if (job != null) {
      if (job.isInInconsistentLockState()) {
        job.resetLock();
      }

      job.setRetries(retries);
    } else {
      throw new ProcessEngineException("No job found with id '" + jobId + "'.");
    }
  }
View Full Code Here

    ensureNotNull("jobId", jobId);

    if (log.isLoggable(Level.FINE)) {
      log.fine("Executing job " + jobId);
    }
    JobEntity job = commandContext
      .getJobManager()
      .findJobById(jobId);

    final CommandExecutor commandExecutor = Context.getProcessEngineConfiguration().getCommandExecutorTxRequiresNew();
    final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();

    if (job == null) {

      if (jobExecutorContext != 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.log(Level.FINE, "Job with Id " + jobId + " was acquired but cannot be found in database.");
        return null;

      } else {
        throw new ProcessEngineException("No job found with id '" + jobId + "'");

      }

    }

    // the failed job listener is responsible for decrementing the retries and logging the exception to the DB.
    FailedJobListener failedJobListener = createFailedJobListener(commandExecutor);

    // the listener is ALWAYS added to the transaction as SNYC on ROLLABCK. If the transaction does not rollback, it is ignored.
    commandContext.getTransactionContext().addTransactionListener(
        TransactionState.ROLLED_BACK,
        failedJobListener);

    // register as command context close lister to intercept exceptions on flush
    commandContext.registerCommandContextListener(failedJobListener);

    if (jobExecutorContext != null) { // if null, then we are not called by the job executor
      jobExecutorContext.setCurrentJob(job);
    }

    try {
      job.execute(commandContext);
      return null;

    } catch (RuntimeException exception) {
      log.warning("Exception while excuting job '" + job + "': " + exception.getMessage());
View Full Code Here

TOP

Related Classes of org.camunda.bpm.engine.impl.persistence.entity.JobEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.