Class ScheduledJobTasklet

  • All Implemented Interfaces:
    org.springframework.batch.core.step.tasklet.StoppableTasklet, org.springframework.batch.core.step.tasklet.Tasklet

    public class ScheduledJobTasklet
    extends java.lang.Object
    implements org.springframework.batch.core.step.tasklet.StoppableTasklet
    Offers a way to run PLSQL code asynchronously. Typically by calling a stored procedure.

    Runs a PLSQL block asynchronously once as a scheduled job using the Oracle DBMS_SCHEDULER. See https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SCHEDULER.html#GUID-A24DEB5D-2EAF-4C0B-8715-30DC947B3F87

    The tasklet starts the block asynchronously and then continuously checks the status of the job in the DB.

    Will essentially run the equivalent of: begin SYS.DBMS_SCHEDULER.CREATE_JOB( job_name=>'MY_JOB123', job_type=>'PLSQL_BLOCK', job_action=>'begin MY_PROCEDURE(''some_argument'',123);end;', enabled=>TRUE); end; /

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String reportDir  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String createSchedulerJobName​(java.lang.String stepName)
      Max length of job name is 30 in older versions of oracle.
      org.springframework.batch.repeat.RepeatStatus execute​(org.springframework.batch.core.StepContribution contribution, org.springframework.batch.core.scope.context.ChunkContext chunkContext)  
      void setAction​(java.lang.String action)  
      void setCheckRunning​(boolean checkRunning)
      Should we continuously check that the scheduled job is indeed running.
      void setForceStop​(boolean forceStop)
      Set the attribute force to TRUE or FALSE in the dbms_schdeduler.stop_job command.
      void setMaxFailedStatusChecks​(java.lang.Integer maxFailedStatusChecks)
      Maximum number of failed attempts to check the status of the scheduler job, before marking the step as FAILED.
      void setSchedulerNameMaxLength​(int schedulerNameMaxLength)  
      void setStatusCheckInterval​(java.lang.Long statusCheckInterval)
      How often to query Oracle and check the status of the scheduled job.
      void stop()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • reportDir

        @Value("${bauta.reportDir}")
        protected java.lang.String reportDir
    • Constructor Detail

      • ScheduledJobTasklet

        public ScheduledJobTasklet()
    • Method Detail

      • setAction

        public void setAction​(java.lang.String action)
        Parameters:
        action - The PLSQL block to run. Typically calls a stored procedure, e.g. "begin my_procedure(''some_argument'', 123);end;"
      • setStatusCheckInterval

        public void setStatusCheckInterval​(java.lang.Long statusCheckInterval)
        How often to query Oracle and check the status of the scheduled job.
        Parameters:
        statusCheckInterval - The interval between checks in ms. Valid values are 10000 - 300000
      • setMaxFailedStatusChecks

        public void setMaxFailedStatusChecks​(java.lang.Integer maxFailedStatusChecks)
        Maximum number of failed attempts to check the status of the scheduler job, before marking the step as FAILED. Default to 5.
        Parameters:
        maxFailedStatusChecks -
      • setSchedulerNameMaxLength

        public void setSchedulerNameMaxLength​(int schedulerNameMaxLength)
      • setCheckRunning

        public void setCheckRunning​(boolean checkRunning)
        Should we continuously check that the scheduled job is indeed running. This is done by checking the USER_SCHEDULER_RUNNING_JOBS
        Parameters:
        checkRunning -
      • setForceStop

        public void setForceStop​(boolean forceStop)
        Set the attribute force to TRUE or FALSE in the dbms_schdeduler.stop_job command.
        Parameters:
        forceStop -
      • stop

        public void stop()
        Specified by:
        stop in interface org.springframework.batch.core.step.tasklet.StoppableTasklet
      • execute

        public org.springframework.batch.repeat.RepeatStatus execute​(org.springframework.batch.core.StepContribution contribution,
                                                                     org.springframework.batch.core.scope.context.ChunkContext chunkContext)
                                                              throws java.lang.Exception
        Specified by:
        execute in interface org.springframework.batch.core.step.tasklet.Tasklet
        Throws:
        java.lang.Exception
      • createSchedulerJobName

        protected final java.lang.String createSchedulerJobName​(java.lang.String stepName)
        Max length of job name is 30 in older versions of oracle. 255 in newer. Oracle also converts it to uppercase. Must not begin with '_', therefor prepending 'J'
        Parameters:
        stepName -
        Returns: