Notification when a group of jobs complete

I have a large number of jobs that I run using a cursor (All jobs start with PS_ and each job loads a single table from ORACLE) so they can run in parallel.  I want to be able to be notified when the last job completes.  Should this done using
a trigger?  Or should I just add a loop statement to the stored procedure that fires this job?  I know which individual takes the longest and I could simply just add a notification to send email on success but I want it to be more robust.  Below
is what I am using to trigger the jobs.
Thanks in advance!
BEGIN
SET NOCOUNT ON;
DECLARE @year CHAR(4)
DECLARE @month CHAR(2)
DECLARE @day CHAR(2)
SET @year = CAST(DATEPART(YEAR, GETDATE()) AS VARCHAR)
SET @month = CASE WHEN LEN(CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR)) = 1
THEN '0'+ CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR)
ELSE CAST(DATEPART(MONTH, GETDATE()) AS VARCHAR)
END
SET @day = CASE WHEN LEN(CAST(DATEPART(DAY, GETDATE()) AS VARCHAR)) = 1
THEN '0' + CAST(DATEPART(DAY, GETDATE()) AS VARCHAR)
ELSE CAST(DATEPART(DAY, GETDATE()) AS VARCHAR)
END
DECLARE @job_name NVARCHAR(255)
DECLARE cur CURSOR
FOR
SELECT name
FROM msdb.dbo.sysjobs X
WHERE SUBSTRING(X.name, 1, 3) = 'PS_'
OPEN cur
FETCH NEXT FROM cur INTO @job_name
WHILE @@fetch_status = 0
BEGIN
CURSOR_START:
--if the job has not completed
IF ( SELECT COUNT(*)
FROM sysjobhistory
WHERE job_id = ( SELECT job_id
FROM sysjobs
WHERE name = @job_name
AND step_id = 0 --job outcome
AND run_status = 1 --0 = failed 1 = success
AND run_date = @year + @month + @day
) = 0
AND
--and the job is not currently running
( SELECT COUNT(*)
FROM sysjobactivity
WHERE job_id = ( SELECT job_id
FROM sysjobs
WHERE name = @job_name
AND CONVERT(VARCHAR(10), start_execution_date, 111) = CONVERT(VARCHAR(10), GETDATE(), 111)
AND stop_execution_date IS NULL
) = 0
BEGIN
IF ( SELECT COUNT(*)
FROM sysjobactivity a1
INNER JOIN sysjobs a2 ON a2.job_id = a1.job_id
WHERE CONVERT(VARCHAR(10), start_execution_date, 111) = CONVERT(VARCHAR(10), GETDATE(), 111)
AND stop_execution_date IS NULL
AND SUBSTRING(name, 1, 3) = 'PS_'
) < 10
BEGIN
PRINT 'EXEC msdb.dbo.sp_start_job @job_Name='
+ CAST(@job_name AS VARCHAR)
EXEC msdb.dbo.sp_start_job @job_Name=@job_Name
WAITFOR DELAY '00:00:10'
END
ELSE
BEGIN
PRINT 'WAIT 10 jobs already running: EXEC msdb.dbo.sp_start_job @job_Name='
+ CAST(@job_name AS VARCHAR)
WAITFOR DELAY '00:00:10'
GOTO CURSOR_START
END
END
ELSE
BEGIN
PRINT CAST(@job_name AS VARCHAR)
+ ' The job is already currently running or completed sucessfully today'
END
FETCH NEXT FROM cur INTO @job_name
END
CLOSE cur
DEALLOCATE cur
END

You can store all jobs name in a table variable or temp variable which you want to monitor and then use below code (this code is just for one job name)
DECLARE @JobStatus INT
SET @JobStatus = 0
EXEC MSDB.dbo.sp_start_job @Job_Name = 'JobName'
SELECT @JobStatus = current_execution_status FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'EXEC MSDB.dbo.sp_help_job @job_name = ''JobName'', @job_aspect = ''JOB'' ')
WHILE @JobStatus <> 4
BEGIN
SELECT @JobStatus = current_execution_status FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'EXEC MSDB.dbo.sp_help_job @job_name = ''JobName'', @job_aspect = ''JOB'' ')
END
SP_Help_Job provides the status of the job
Value
Description
0
Returns only those jobs that are not idle or suspended.
1
Executing.
2
Waiting for thread.
3
Between retries.
4
Idle.
5
Suspended.
7
Performing completion actions.

Similar Messages

  • Send different email notifications when a request is rejected/completed

    Hi Friends,
    I have developed a SOA composite in OIM 11g. And I am getting the same email notification when a request is fully completed or when it is rejected by an approver. How to send diffrerent email notification when a request is completed and when it is rejected by an approver.

    There are multiple ways in which you can do it.
    1. Modify your SOA composite and change the notification properties in the .task. Here change the status of the event and configure different notifications for different events.
    2. Use the Request Status change plugin in OIM to send the notification and remove all notification from SOA composite.
    3. Use explicit notification service in the SOA composite and attach the notification service component at appropriate places in the SOA workflow. Additionally remove the notification configuration from the .task
    -Bikash

  • To show the list in complete format when creating an background job

    Hi ,
    I need to show the list in full format when after running a report in background.
    In sm37 after the job run the the full list is not shown.
    when I click on 'Show complete list 'it will show the complete list.
    My requirement is I want this option in default .Is there any thing we can do by configuration or is there any chance of enhancement
    kindly help
    thanks and regards,
    Subeesh Kannottil

    Hi Subeesh,
    It is one of the standard setting provided by SAP for extracting spool output.In most of the case it is sufficient. Incase of special requirement we can do as below.
    In SM37,open the spool and click the icon Display in Maximum Width or (Shift+F4). Then the complete list will be displayed.
    Regards,
    Kannan

  • Dbms_datapump - How to ennusre pl/sql only completes when job completes -

    Hi,
    Calling dbms_datapump via pl/sql - when look at outpurt directory where log and export file are created it seems to take a while but pl/sql comes back saying complete far earlier.
    Uisng 11.2.0.3
    Want pl/sql to show complete only when actually complete.
    Seems tobe running in background.
    declare
      -- Local variables here
      i integer;
    h1 number; -- Datapump handle
      dir_name varchar2(30); -- Directory Name
    v_file_name varchar2(100);
      v_log_name  varchar2(100); 
    v_job_status ku$_Status;          -- The status object returned by get_status
        v_job_state VARCHAR2(4000);
        v_status ku$_Status1010;
        v_logs ku$_LogEntry1010;
        v_row PLS_INTEGER;
        v_current_sequence_number archive_audit.aa_etl_run_num_seq%type;
       v_jobState                user_datapump_jobs.state%TYPE;
    begin
    --execute immediate ('alter tablespace ARCHIVED_PARTITIONS read only');
    -- Get last etl_run_num_seq by querying public synonym ARCHIVE_ETL_RUN_NUM_SEQ
    -- Need check no caching on etl_run_num_seq
    select last_number - 1
    into v_current_sequence_number
    from ALL_SEQUENCES A
    WHERE A.SEQUENCE_NAME = 'ETL_RUN_NUM_SEQ';
    v_file_name := 'archiveexppre.'||v_current_sequence_number;
    v_log_name  := 'archiveexpprelog.'||v_current_sequence_number;
    dbms_output.put_line(v_file_name);
    dbms_output.put_line(v_log_name);
    -- Create a (user-named) Data Pump job to do a schema export.
      dir_name := 'DATA_EXPORTS_DIR';
      h1 := dbms_datapump.open(operation =>'EXPORT',
      job_mode =>'TRANSPORTABLE',
      remote_link => NULL,
      job_name    => 'ARCHIVEEXP10');--||v_current_sequence_number);
      dbms_datapump.add_file(handle =>h1,
                             filename => v_file_name,
                             directory => dir_name,
                             filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE,
                             reusefile => 1); -- value of 1 instructs to overwrite existing file
      dbms_datapump.add_file(handle =>h1,
                             filename => v_log_name,
                             directory => dir_name,
                             filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE,
                             reusefile => 1); -- value of 1 instructs to overwrite existing file
      dbms_datapump.metadata_filter(     
          handle => h1,
          name   => 'TABLESPACE_EXPR',
         VALUE    => 'IN(''ARCHIVED_PARTITIONS'')'
    --dbms_datapump.metadata_filter(handle =>h1,
      --                       name => 'TABLE_FILTER',
      --                       value => 'BATCH_AUDIT');
    -- Start the datapump_job
    -- dbms_datapump.set_parameter(h1, 'TRANSPORTABLE', 'ALWAYS');
      dbms_datapump.start_job(h1);
      begin
        null;
        -- dbms_datapump.detach(handle => h1);
      end;
    dbms_datapump.wait_for_job(h1,v_jobState);
    dbms_output.put_line('Job has completed');
    exception
        when others then
          dbms_datapump.get_status(handle => h1,
                                 mask => dbms_datapump.KU$_STATUS_WIP,
                                 timeout=> 0,
                                job_state => v_job_state,
                                status => v_job_status);
                   dbms_output.put_line(v_job_state);
         RAISE_APPLICATION_ERROR(-20010,DBMS_UTILITY.format_error_backtrace);
    end;causes this.
    How do I ensure the pl/sql job only completes when the dbms_daatpump job completes i.e. runs in the foreground.
    Tried adding dbms_datapump.wait_for_job(h1,v_jobState);
    but get message job is not attached to this session when add this.
    Removed dbms_datapump.detach and now wokrs O.K - seems that dbms_datapump.detach + wait for job are mutually exclusive?
    Thanks
    Edited by: user5716448 on 28-Sep-2012 06:37
    Edited by: user5716448 on 28-Sep-2012 06:37
    Edited by: user5716448 on 28-Sep-2012 06:38
    Edited by: user5716448 on 28-Sep-2012 06:47
    Edited by: user5716448 on 28-Sep-2012 06:50

    user5716448 wrote:
    Removed dbms_datapump.detach and now wokrs O.K - seems that dbms_datapump.detach + wait for job are mutually exclusive?
    If you want your block to WAIT till datapump finishes, why are you detaching? detach means you are no longer interested once the job has started. Remove the detach and keep the wait_for_job as you have found out.

  • PM Notification Workflow - Notify orginator of notification when completed

    Hi all,
    I am new to workflow and I have a customer requirement to notify the creator of a notification when the order has been compelted. What is the best way to handle this request? Notification is created then coverted to Maintenance Order by techincian then the order is compelted by technician and this compeltes the Notification. I have activated workflow WS20000317 but I do not know how to modify WF to notify the originator of the notification when completed.

    Mike,
      This standard WF might not be suitable for your requirement. There are various ways to satisfy your requirement.
    You could use the the user exit IWO10004(Maintenance order: Customer check for order completion) or IWO10009 (Maintenance order: Customer check for "Saving") to send a email to the originator using the FM SO_NEW_DOCUMENT_SEND_API1(or other send email FM).
      If you would like to keep these outside the standard flow, then you could create a separate standard task which basically calls a method in a business object to send a email.You could trigger this when the system status of the order is changed to TECO through config using transaction BSVW.
    Regards
    Narasimhan

  • Cisco Tidal 5.3.1 Job Group with (2) completed and the first job group (1) still waiting on Dependency.

    We have a job group i.e. Job Group A that creates a second instance of the job group Job Group A (2) and completes normally. The problem is we have another job group that is dependent on Job Group A (1) so it never runs until we cancel the first job group or set it as completed. What could be inserting the Second occurrence of the JOB Group?  

    This sounds like a repeating job/group with new occurrences. Check out the Options tab for both group and job-levels
    Group Options, If job is running, then Run Anyway
    Job Options, If job is running, then Run Anyway
    The correct setting should be:
    Group Options, If job is running, then Run Anyway
    Job Options, If job is running, then Defer until Normal or Defer Until Complete
    which means if any of the deferred options are selected, the second occurrence will wait until job is completed normally (Defer Until Normal), or wait until job either completes normally or abnormally (Defer Until Complete)
    Now I wonder what causes the second instance to complete normally and not the first instance.
    BR,
    Derrick Au

  • Notification when report complete

    Is there a way in Forms (or Discoverer) to notify a user when an Oracle Form is completed running in Batch mode? Can it notify if a report fails?
    Can you setup notification during the scheduling of the report?

    DECLARE
    repid REPORT_OBJECT;
    v_rep VARCHAR2(100);
    rep_status varchar2(20);
    BEGIN
    repid := find_report_object('report4');
    v_rep := RUN_REPORT_OBJECT(repid);
    rep_status := REPORT_OBJECT_STATUS(v_rep);
    if rep_status = 'FINISHED' then
    message('Report Completed');
    copy_report_object_output(v_rep,'d:\temp\local.pdf');
    host('netscape d:\temp\local.pdf');
    else
    message('Error when running report.');
    end if;
    END;

  • Product Import Never Notifies When Finished and Successful

    For over a year now it seems BC never notifies when a product import has successfully completed, if you are importing more than a couple hundred records. This happens whether you use IE, Firefox, or Chrome in Windows, and it happens in the many different BC sites I import products into.
    The import begins and the loading spinner appears, but it stays stuck on this forever and never goes to the screen to tell you the import is done. You therefore have no way to know if the import finishes correctly or not. It's frustrating because if you abort the import screen too early you harm the import, so you have to wait forever to be sure you've allowed enough time for it to complete.
    After you abort, the only method to know if it worked is in your last record of the import file, have some changed info that you can later lookup in BC Admin to see if it transferred.
    Presenlty if I try to import more than 500 records at a time it will always fail.

    Had to import 42,000 products. Found I can split the CSV or TXT file into pieces using a free program like GSplit into 2000 record subfiles and import those OK. While there is no notification from BC when the import is done running, testing shows that it takes a little less than 25 minutes for BC to import 2000 products, so after that time I can kill the never-ending BC job, then check in BC product search to verify if the last product in my import file has in fact been imported without error.
    Took more than 11 hours to complete the import this way.
    Looking forward to the release of the new BC import/export software as soon as possible...

  • Unable to create a notification for a group (Cisco Unity Express 3.2)

    There is Cisco ISR 2821 with CME 7.1 and Cisco Unity Express 3.2.
    I am trying to create notifications for a group named AAA in CUE.
    I do following (GUI):
    1. Go to Configure -> Groups
    2. Click on the group name AAA.
    3. In Group Profile window 'Enable notification for this user/group' option is enabled.
    4. Go to Mailbox tab. There is an associated mailbox with ticks against Enabled and Fax Enabled.
    5. Go to Notification tab and see the warning:
    No Notification Devices found for User/Group
    Also, there are another several groups on this system and I am able to turn notification on for them. These groups have the same owners and members that AAA has. Moreover, if I create a new group and set it up absolutely the same as AAA, I can turn notifications on for it.
    The problem in this way is that we have our custom greetings and after I created a new group, for example BBB, with the same settings (as AAA, inluding Primary Extansion and Primary E.164 Number) and remove these numbers from AAA, then it works and users would receive notification about new voice messages. BUT, when I call BBB I listen to standart Cisco greeting promts.
    I don't undestand why it happens, because all these greetings are determined in Voicemail -> Auto Attendant section and I did not any changes here at all.
    How can I fix this 'notification' problem?
    Thanks.

    Process with success:
    unzip the packet in: C:\APEX
    1. Install:
    @apexins SYSAUX SYSAUX TEMP /i/
    2. Change to password:
    @apxchpwd,
    3. Run apex_epg_config.sql
    On windows:
    @apex_epg_config.sql (page 30, the guide of intallation)
    Important:Replace SYSTEM_DRIVE:\TEMP by C:
    E.g.: @apex_epg_config C:
    After this, follow the next steps
    4. ALTER USER ANONYMOUS ACCOUNT UNLOCK;
    Finish! Just execute apxldimg.sql script if you is upgrading from a preview release.
    Now try the connect on the browser IE6 o later:
    http://localhost:8080/apex/apex_admin
    Then create your workspace.
    Edited by: [email protected] on 10/03/2009 11:59

  • R3 job completion trigger a process chain to run on BW

    Hello,
    I was wondering how I can trigger a process chain to run on BW 3.5 after a SM37 job completes on R3?
    I have been searching the forums and the web, but I haven't found what I am looking for.
    Thanks,
    Nick

    Hello Pramod,
    I would need a more detailed suggestion to implement, but thanks for starting the discussion.
    I thought it would be as easy as this
    1. Create an event in BW
    2. Have a process chain that starts when that event is raised.
    Having implemented and successfully tested steps 1 and 2, the rest should be simple (I was able to raise the event on BW locally and the chain did run as expected)
    3. On R3, create a small ABAP program that calls the BP_EVENT_RAISED Function Module on R3.
    4. Pass that Function Module the following parameters
            A. My BW system name, and
            B. The event name that I created on my BW system
    5. Add that ABAP program to the end of the job on R3.
    It doesn't work though! The event i created on BW, doesn't seem to exist from R3's perspective.  I was hoping it was as easy as that.  Hopefully I am missing something simple, but so far R3 does not want to cause the event on BW to be raised.
    Thanks,
    Nick
    Edited by: Nick Bertz on Oct 13, 2008 12:19 PM
    Edited by: Nick Bertz on Oct 13, 2008 12:23 PM

  • Avoid Duplicate Tasks when Expanding Groups for Custom Task Process

    Is there a way to:
    Avoid Duplicate Tasks when Expanding Groups for Custom Task Process?
    I've got a people metadata column that I am planning on putting groups into.  I want the groups to expand and send a task for all users in the groups.  I also want to avoid creating multiple tasks if a user happens to be in two groups at the same
    time.
    I'm trying to work out a way to assign users a read task based on job training requirements.  Right now assigning groups and using a workflow task to confirm read is what I'm trying to accomplish.  I just end up getting two tasks for a user if
    their in multiple groups.
    David Jenkins

    Hi David,
    Please verify the followings:
    After Participants, select Parallel(all at a once)
    Expand Task Options, select ‘Assign a task to each member within groups’
    Open the action properties, make sure ExpandGroup is Yes
    Also in SharePoint Designer ,you can edit the property for the Start Approval Porcess to enable ExpandGroup:
    Reference:
    https://social.msdn.microsoft.com/Forums/office/en-US/d14da1c4-bd5a-459b-8698-3a89bb01e6ad/expand-groupnot-creating-tasks-for-users-issue-in-sharepoint-2013-designer-workflow?forum=sharepointgeneral
    https://social.technet.microsoft.com/Forums/office/en-US/ac245d45-ff66-4341-815c-79213efc4394/sharepoint-2010-designer-workflows-and-sharepoint-user-groups?forum=sharepointcustomizationprevious
    Best Regards,
    Eric
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Process chain node is in yellow colour but job completed successfully

    Hi All,
    I have one master data load process chain. This process chain have one child process chain also. Parent process chain was showing Fail for one child process chain. When I checked child process chain I got to know that one info package is still in the running state. When I checked the monitor of the data load , It is showing successful data load , even i have checked in batch job log , it is also showing ' JOB COMPLETED SUCCESSFULY'.
    Now as this node is in ruuning state , all lined up process are on hold.
    Please help me with this issue.
    Thanks in advance.

    hi,
    open the child process chain, right click on the variant at which it is struck. note down the details such as log instance,variant.
    open table rspcprocesslog in SE12 ,give the details of variant and job logs and find the instance id.
    open tcode se38 ,enter program RSPC_PROCESS_FINISH.
    execute it, enter the details obtained from table rspcprocesslog table for the same and set the status to "G" and execute.
    the process chain will be triggered.
    regards,
    Arvind.

  • Multiple email notification for scheduled web intelligence jobs

    Hi,
    Webi job failed email notification for daily scheduled jobs, email count goes more than 2000.
    Operating System Details:
    Windows 2008 R2
    SAP Business Objects Details:
    SAP BO 4.0 SP6
    Database Details:
    CMS DB Oracle 11.2.1.0
    Issue description:
    On daily basis 100 jobs are scheduled using event file. All 100 jobs start after BW data load completion.
    Below is the process for webi job schedule start.
    1) BW job complete
    2) Event file update on shared location 
    3) Webi job scheduling starts.
    Till april 1st week all 100 jobs were scheduled succesfully  and we recieved 101 notification, 1 extra mail for event file notification. 
    But from last week we recieved more than 2000 mail and on subsequent retry all jobs were scheduled succesfully.
    We check the CUID in query builder, but only data for 16 jobs was available, and in instance manager we got 300 failed instances of 16 jobs, but those jobs were executed successfully after multiple reattempt.
    Below is the error mentioned in instance manger for all 300 instances:
    "Object could not be scheduled within the specified time interval".
    Note : Due to unavailablity of trace log, we cannot enable the trace log in enviornment.
    Thanks,
    Vizit Yadav

    Hi Vijay,
    Thanks for reply.
    I have read the KB#144881- Multiple instances spawned after daylight savings time change.
    Though this issue arrived after daylight saving, i have few more points to describe:
    1. Issue arrives only on Monday, not on every day.
    2. Day light saving was on 29th March, after that at the very first Monday on 30th March issue was not       there, however after that issue arrives every Monday, i.e. 6th & 13th of April.
    Is there any SAP notes for SAP-BO 4.0 SP 6 on this.
    Regards,
    Vizit

  • Job completed but status showing still yellow

    Hi Experts,
    One of full load status tab showing yellow, but the job completed when i checked in SM37.
    I am loading from ODS to Cube there is no PSA. we are using 3.5 version.

    Hi David,
    Check the load in the details tab weather all the data packets are in green status.If at all the idocs are hung or TRFCs are hung you may face this issue. try to manually flush the hung Idocs and TRFCs.
    If everything is fine wait for the PID  process to finish- some times it happen the PID might be running at the background.
    If everything is fine n the status of the request is yellow -try to change the status of the load to green.
    Regards
    KP
    Edited by: prashanthk on Oct 5, 2010 2:22 PM

  • IPhone Mail Notification when Mail Read Elsewhere (not resetting)

    I'm using the built in mail application with Yahoo Mail.  I've configured Push notification and have Mail configured to place an icon badge indicating the number of unread messages.  This works, mostly.  Occasionally, it doesn't notify when I get new mail (but this is rare).
    However, if I read my Yahoo Mail elsewhere, the badge notifiation remains on the iPhone.  Yahoo uses POP.  I'm not particularly familiar with the protocols and how they are supposed to work.  Does the iPhone receive a notification when email is read elsewhere (or deleted or moved)?  It doesn't appear that it this happens, as I often see out of sync email when opening my mailbox (until the phone catches up and resyncs). 
    Would turning on Fetch instead of Push mode be helpful?  I don't see a method for enabling both (which might be a nice compromise). 
    Do other email apps do a better job?  Is Yahoo Mail doing something wrong?
    Thanks for any insight. 

    Thanks.  Why not? 
    Is this a limitation of the protocol?  An application decision?  A bug? 
    I wouldn't think that it's a desired behaviour, but could imagine that it might be a compromise due to other constraints. 
    Also, is this true regardless of the email provider?  Same for IMAP? 

Maybe you are looking for

  • How do i get kids games to be available on there user login

    i got 2 games for my 3 year old -go diego and dora. when i log in under my sons name i cannot play the games. I can only play them under my log in. he has done a heck of a job messing up my screen and i would like him to only be able to play on his l

  • How do you change the weather temperature from Celsius to fahrenheit?

    Hi my name is Paul, gotta say that the "iPad Mini" is one of the best apple device's in the history of apple. But theres something now working right.. Every time i ask siri something about the weather temperature, siri tells me in "Celsius not Fahren

  • App for down payment request

    hi all, can any one give a configuration steps to run app for down payment request for vendors. this can be done through t code : F111 i appreciated for ur affairs. regards, supriya thodimela.

  • How do I update the requested quantity on an approved move order?

    Hi, can anybody tell me what would be the normal process if I want do update the quantity of an approved, but not transacted move order? Looks like I cannot do any chances if move order is approved, right? Would I create an additional line in case of

  • Downloading Adobe month by month sub after 30 day trial

    Hi I purchased Adobe XI after using it as a trial for 30 days.  The receipt came through and I clicked the download button.  The download initialises o.k. however there is an error message that comes up briefly but goes so fast I am unable to see wha