1 Reply Latest reply on Jun 5, 2014 5:50 AM by GregV

    Query on event based job in a client schema and not SYS schema

    999847

      Hi, I am fairly new to oracle job scheduler and wanted your inputs on how to create a event based job that sends a mail based on success of another job.


      I was able to implement this with the jobs being created under SYS schema. I did get email notifcation when errors were logged in exception table.

      However, now the requirement has changed to create the jobs under a client specific schema.

      The jobs got created successfully in CLIENT schema but the event based job is not working. It does not send the email notification.


      I feel this is to do with not correctly subscribing to the event queue {sys.scheduler$_event_queue}.


      Can CLIENT schema use the agent "AGENT" created under SYS to subscribe to the Scheduler event queue {sys.scheduler$_event_queue}? CLIENT is the schema in which the all jobs and procedures are created.


      BEGIN

      DBMS_AQADM.ENABLE_DB_ACCESS('AGENT', 'CLIENT');

      END;

      /


      --Main Job that will load data and errors will be logged into exception table

      BEGIN    

      dbms_scheduler.create_job( job_name=> 'CLIENT.LOAD_DATA',                              

      job_type=>'PLSQL_BLOCK',                              

      job_action=>'BEGIN  CLIENT.p_loaddata;                                     

      END;',                              

      start_date=>systimestamp,                              

      repeat_interval=>'FREQ=MINUTELY;INTERVAL=1;',                              

      number_of_arguments=>0,                              

      enabled=> true);

      END;

      --set raise_events attribute = job_succeeded for main job

      BEGIN

      DBMS_SCHEDULER.set_attribute ('CLIENT.LOAD_DATA', 'raise_events', DBMS_SCHEDULER.job_succeeded);

      END;

      /

      --Event Job that will send email based on condition. Condition is checked in procedure CLIENT.p_check_sendmail; If errors are found in the exception table, this job will raise exception and will be JOB_FAILED status. This job will send a email notification.

      BEGIN 

      DBMS_SCHEDULER.create_job (       job_name          => 'CLIENT.EMAIL_JOB',     

      job_type          => 'PLSQL_BLOCK',     

      job_action        => 'BEGIN  CLIENT.p_check_sendmail;                                   END;',     

      event_condition  => 'tab.user_data.event_type = ''JOB_SUCCEEDED'' and tab.user_data.object_name = ''LOAD_DATA''',      

      queue_spec        => 'sys.scheduler$_event_queue,AGENT',      

      enabled          => true);

      END;

      /

      BEGIN    

      dbms_scheduler.add_job_email_notification ( job_name => 'CLIENT.EMAIL_JOB',     recipients => 'abc@company.com',events => 'JOB_FAILED');

      END;

      /   

      Is the way i am subscribing to the event queue correct? Could you please share an example/document of event based job in a schema other than SYS and how subscription is being done to event queue?
      Thanks

        • 1. Re: Query on event based job in a client schema and not SYS schema
          GregV

          Hi,

           

          It's a good decision you made because you shouldn't create objects in the SYS schema. I see you're using the add_job_email_notification procedure, so I'm assuming you're on 11g onwards.

          This procedure is meant to make the job easy for you. That is, you don't need to worry about setting up AQ, the procedure does it all for you. All you need to do is setup the mail server if not already done, and call this procedure to add the mail notification. That's it.

          You can also specify a filter to the add_job_email_notification procedure, so maybe you could specify directly your CLIENT.LOAD_DATA job to this procedure.