Simple implementation of executing the step as a call to a ITasklet, possibly repeated, and each call surrounded by a transaction. The structure is therefore that of a loop with transaction boundary inside the loop. The loop is controlled by the step operations (StepOperations=RepeatOperations)). Clients can use interceptors in the step operations to intercept or listen to the iteration on a step-wide basis, for instance to get a callback when the step is complete. Those that want callbacks at the level of an individual tasks, can specify interceptors for the chunk operations.
Inheritance: AbstractStep, IDisposable
        public void RunTestSynchronousExecutor()
        {            
            SimpleJobLauncher launcher = new SimpleJobLauncher();
            IJobInstanceDao jobInstanceDao = new MapJobInstanceDao();
            IJobExecutionDao jobExecutionDao = new MapJobExecutionDao();
            IStepExecutionDao stepExecutionDao = new MapStepExecutionDao();
            IExecutionContextDao executionContextDao = new MapExecutionContextDao();

            IJobRepository jobRepository =
                new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
            launcher.JobRepository = jobRepository;

            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props2 = new NameValueCollection
            {
                {"+dateDebut(date)", "1970/07/31"},
                {"+everything(long)", "42"},
                {"-balance(double)", "1000.0"},
                {"+name(string)", "thierry"},
                {"-default", "default"}
            };
            JobParameters jobParameters = converter.GetJobParameters(props2);

            IJob job = new SimpleJob("myTestJob");
            job.JobParametersValidator = new DummyValidator();
            job.Restartable = false;
            TaskletStep step = new TaskletStep("simpleTS")
            {
                JobRepository = jobRepository,
                Tasklet = new MyDummyTasklet()
            };
            ((SimpleJob)job).AddStep(step);
            ((SimpleJob) job).JobRepository = jobRepository;
            JobExecution jobExecution = launcher.Run(job, jobParameters);
            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning()); 
        }
Example #2
0
 /// <summary>
 /// Custom constructor
 /// </summary>
 /// <param name="chunkContext"></param>
 /// <param name="semaphore"></param>
 /// <param name="owner"></param>
 public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore, TaskletStep owner)
 {
     _chunkContext = chunkContext;
     _stepExecution = chunkContext.StepContext.StepExecution;
     _semaphore = semaphore;
     _ownerStep = owner;
 }
        public void RunTestSystemCommandTasklet()
        {
            SimpleJobLauncher launcher = new SimpleJobLauncher();
            IJobInstanceDao jobInstanceDao = new MapJobInstanceDao();
            IJobExecutionDao jobExecutionDao = new MapJobExecutionDao();
            IStepExecutionDao stepExecutionDao = new MapStepExecutionDao();
            IExecutionContextDao executionContextDao = new MapExecutionContextDao();

            IJobRepository jobRepository =
                new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao);
            launcher.JobRepository = jobRepository;

            DefaultJobParametersConverter converter = new DefaultJobParametersConverter();
            NameValueCollection props2 = new NameValueCollection
            {
                {"+dateDebut(date)", "1970/07/31"},
                {"+everything(long)", "42"},
                {"-balance(double)", "1000.0"},
                {"+name(string)", "thierry"},
                {"-default", "default"}
            };
            JobParameters jobParameters = converter.GetJobParameters(props2);

            IJob job = new SimpleJob("myTestJob");
            job.JobParametersValidator = new DummyValidator();
            job.Restartable = false;
            TaskletStep step = new TaskletStep("simpleTS") {JobRepository = jobRepository};
            SystemCommandTasklet tasklet = new SystemCommandTasklet
            {
                Command = "DEL MyDummyTasklet2_out_*.txt",
                WorkingDirectory = "C:/temp",
                Timeout = 10000000,
                SystemProcessExitCodeMapper = new SimpleSystemProcessExitCodeMapper()
            };
            step.Tasklet = tasklet;
            step.RegisterStepExecutionListener(tasklet);
            ((SimpleJob)job).AddStep(step);
            ((SimpleJob)job).JobRepository = jobRepository;
            ITaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
            launcher.TaskExecutor = taskExecutor;
            JobExecution jobExecution = launcher.Run(job, jobParameters);
            //wait for execution end (asynchronous)            
            Assert.IsFalse(jobExecution.Status.IsUnsuccessful());
            Assert.IsFalse(jobExecution.Status.IsRunning());
        }
Example #4
0
 /// <summary>
 /// Custom constructor
 /// </summary>
 /// <param name="chunkContext"></param>
 /// <param name="semaphore"></param>
 /// <param name="owner"></param>
 public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore, TaskletStep owner)
 {
     _chunkContext  = chunkContext;
     _stepExecution = chunkContext.StepContext.StepExecution;
     _semaphore     = semaphore;
     _ownerStep     = owner;
 }