3 Replies Latest reply on Dec 2, 2016 4:37 PM by Cheng Fang

    Run a job starting at a specific step

    Richard Moore Master

      Suppose we have a job with the steps -

      1. Extract data from database.
      2. Make a backup.
      3. FTP data to endpoint.

      There are times when a previous day's data may need to be sent. Is there any way to run a job and start it at a specific step, such as, step3?

        • 1. Re: Run a job starting at a specific step
          Richard Moore Master

          I just realized that we might have already solved this. Is this what we would do -

          1. start job

          2. job listener beforeJob use JobContextImpl.getJobExecution().setRestartPosition(stepIdName)



          For future reference, here is the code we are using in #2 above that is working -


          import java.util.logging.Logger;



          import javax.batch.api.listener.AbstractJobListener;

          import javax.batch.runtime.context.JobContext;

          import javax.enterprise.context.Dependent;

          import javax.inject.Inject;

          import javax.inject.Named;



          import org.jberet.runtime.context.JobContextImpl;



          import com.awginc.batch.JavaBatchExecutor;





          public class JobRestartListener extends AbstractJobListener {



            private JobContext jobContext;




            public void beforeJob() throws Exception {

            JobContextImpl jci = (JobContextImpl) jobContext;


            String restartPosition = System.getProperty(JavaBatchExecutor.restartStep);

            if (restartPosition != null) {

            log.info("Restarting in " + restartPosition);


            } else {

            String startPosition = System.getProperty(JavaBatchExecutor.startStep);

            if (startPosition != null) {

            log.info("Starting in " + restartPosition);






            private final Logger log = Logger.getLogger(this.getClass().getSimpleName());


          • 2. Re: Run a job starting at a specific step
            Cheng Fang Master

            Support custom restart step/position


            We recently added support for specifying custom restart position as job parameter, without using JBeret internal API.


            params.setProperty("jberet.restart.position", "step1");

            jobExecutionId = jobOperator.restart(jobExecutionId, params);


            For more details, see the tests (testRestartPosition1, testRestartPosition2, testRestartPosition3) in the above issue.