Ejemplo n.º 1
0
  /**
   * Execute the Step via Job.runStep(). Setup NDC logging so the Step has its own log file. Remove
   * the NDC logging once the step is finished executing. Notify the ContainerStepListeners when the
   * step starts and finishes.
   */
  @Override
  public void run() {
    Date stepRunDate = dateTimeService.getCurrentDate();
    batchStepFile.setStartedDate(stepRunDate);
    batchStepFile.setStepIndex(new Integer(stepIndex));

    setupNDCLogging();
    notifyStepStarted();

    try {
      LOG.info("Running " + batchStepFile);

      boolean result =
          Job.runStep(parameterService, batchStepFile.getJobName(), stepIndex, step, stepRunDate);

      if (result) {
        LOG.info("Step returned true");
        batchContainerDirectory.writeBatchStepSuccessfulResultFile(batchStepFile);
      } else {
        LOG.info("Step returned false");
        batchContainerDirectory.writeBatchStepErrorResultFile(batchStepFile);
      }

    } catch (Throwable throwable) {
      LOG.info("Step threw an error: ", throwable);
      batchContainerDirectory.writeBatchStepErrorResultFile(batchStepFile, throwable);

    } finally {

      notifyStepFinished();
      resetNDCLogging();
    }
  }
Ejemplo n.º 2
0
  /** Notify the ContainerStepListeners that the Step has completed */
  private void notifyStepFinished() {
    BatchStepFileDescriptor resultFile = batchContainerDirectory.getResultFile(batchStepFile);
    resultFile.setCompletedDate(dateTimeService.getCurrentDate());
    resultFile.setStepIndex(new Integer(stepIndex));

    String shortLogFileName = getShortLogFileName();

    for (ContainerStepListener listener : this.containerStepListeners) {
      listener.stepFinished(resultFile, shortLogFileName);
    }
  }