Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when a procedure executed by a JOB is not finished when is time for the JOB to execute it again?

I want to know what happens when a procedure is executed through a job and before it finishes is time for the job to call the next execution of the procedure. Here the job I created:

DECLARE
  X NUMBER;
    BEGIN
      SYS.DBMS_JOB.SUBMIT
       (
          job        => x
         ,what       => 'BEGIN PKG_DISTRIBUIDOR_SCHEDULER.PRC_DISTRIBUYE_TRANSACCIONES(5000); END;'
         ,next_date  => to_date(sysdate,'dd/mm/yyyy hh24:mi:ss')
         ,interval   => 'SYSDATE+30/86400'
         ,no_parse   => FALSE
       );
       DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));   
       COMMIT;
   END;

As you can see, the job is executed each 30 seconds. So if my procedure (PRC_DISTRIBUYE_TRANSACCIONES) delays more than 30 seconds, what does the job do in this case?

like image 271
Edgar Hernandez Avatar asked May 22 '19 19:05

Edgar Hernandez


People also ask

How to check job execution time in Oracle?

You will have to monitor dba_scheduler_job_run_details to see the status of the job run but you can easily use log_date to figure out which row is your row. Just select the row with log_date > sysdate when you called run_job. If that run succeeds, you will manually need to call drop_job. - use dbms_scheduler.

How to stop DBMS_SCHEDULER running jobs in Oracle?

Stopping running jobs When a job is running and you want to stop it, you can run the STOP_JOB procedure as follows. BEGIN DBMS_SCHEDULER. stop_job (JOB_NAME => 'RMAN_INC'); END; STOP_JOB will attempt to gracefully stop a job.

How do I run two stored procedures in parallel Oracle?

Using DBMS_SCHEDULER to run things in parallel is by far the easiest and most common way to achieve this result. Of course it's going to consume more resources, that's what parallelism will inevitably do. Another, poorer option, is to use parallel pipelined table functions.


1 Answers

If you use the (old deprecated) Jobs, i.e. DBMS_JOB

The starting time for the next execution is determined when the current jobs is finished. If you specify an interval as SYSDATE+30/86400 then it does not mean: "The job runs every 30 seconds."

It means: "The next jobs starts 30 seconds after the previous job has been finished."

If you use the Scheduler Jobs, i.e. DBMS_SCHEDULER

Immediately after a job starts, the repeat_interval (e.g. FREQ=SECONDLY;INTERVAL=30) is evaluated to determine the next scheduled execution time of the job. While this might arrive while the job is still running, a new instance of the job does not start until the current one completes. See About Setting the Repeat Interval

So it means: If a jobs last longer than 30 seconds then the new job will start immediately after the previous job has been finished.

like image 98
Wernfried Domscheit Avatar answered Sep 23 '22 19:09

Wernfried Domscheit