예제 #1
0
  public Object execute(Environment environment) throws Exception {
    log.debug("handling job " + jobDbid + " exception: " + exception.getMessage());

    // load the job from the db
    DbSession dbSession = environment.get(DbSession.class);
    if (dbSession == null) {
      throw new JbpmException("no job-session configured to handle job");
    }
    JobImpl job = dbSession.get(JobImpl.class, jobDbid);
    // serialize the stack trace
    StringWriter sw = new StringWriter();
    exception.printStackTrace(new PrintWriter(sw));
    if (job != null) {
      // decrement the number of retries
      int decrementedRetries = job.getRetries() - 1;
      log.debug("decrementing retries to " + decrementedRetries + " for " + job);
      job.release();
      job.setRetries(decrementedRetries);
      job.setException(sw.toString());

      // notify the job executor after the transaction is completed
      Transaction transaction = environment.get(Transaction.class);
      JobExecutor jobExecutor = environment.get(JobExecutor.class);
      if ((transaction != null) && (jobExecutor != null)) {
        log.trace("registering job executor notifier with " + transaction);
        transaction.registerSynchronization(new JobAddedNotification(jobExecutor));
      }
    }
    return null;
  }
  public Map<String, Object> execute(Environment environment) throws Exception {
    Map<String, Object> variables = new HashMap<String, Object>();

    DbSession dbSession = environment.get(DbSession.class);
    TaskImpl task = dbSession.get(TaskImpl.class, Long.parseLong(taskId));
    for (String variableName : variableNames) {
      Object value = task.getVariable(variableName);
      variables.put(variableName, value);
    }

    return variables;
  }