/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code usage Note: This program xwr_jbinit is included by xwr_start Filename _WRCode. Notes: - _WRjbloc (libref) is the location for all control data during the polling. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* * * xwr_jbinit Verify what code could run and when conditions are met, start it. * * * */ /* * * Chekcing status on pending jobs for: * * * */ /* * * - Date time * * * */ /* * * - Other jobs (by job-id) * * * */ /* * * - Filename existance (true/false) * * * */ /* * * - table existance (true/false) * * * */ /* * * - bypass conditions wait for a job when a dedicate filename exists * * * */ /* * * Submit job when there are no blockking conditions * * * */ data _WRjbloc.&jbdata (drop=curdatetim seljobsubmit selnodelaymsg submitstring filcheck1 filcheck2 i errmsg dsnamtst dsid rcdsid) ; set _WRjbloc.&jbdata ; file print notitles; length submitstring $2048 filcheck1 $250 filcheck2 $200; curdatetim=datetime(); format curdatetim datetime. ; seljobsubmit = 0 ; array trgjb{*} trgjbid: ; array blkjb{*} blkjbid: ; array trgfil{*} trgfil: ; array blkfil{*} blkfil: ; array trgdsn{*} trgdsn: ; array blkdsn{*} blkdsn: ; if ( jbstatus= " ") then do; if ( jbwinstart > jbwinend & jbwinstart ne . & jbwinend ne . ) then do; jbstatus="F" ; put "WR jbinit: " jbid "met source:" source "disapproved start time > end time " jbwinstart jbwinend ; end ; end; if ( jbstatus= " ") then do; if ( ( srcloc= "" or usrloc =" " ) & source ne " " ) then do; JBstatus="F"; put "WR jbinit: jbid srcloc usrloc left empty? not allowed: " srcloc " - " usrloc " - " ; end ; if ( source = "" & jbwintype = " " ) then do; JBstatus="F"; put "WR jbinit: source and jbwintype both left empty? not allowed: " srcloc " - " usrloc " - " ; end ; end; if ( jbstatus= " " & source ne " " ) then do; filcheck1= "&bdapploc/"||trim(srcloc)||"/"||trim(source)||".sas" ; filcheck2= "&bdapploc/"||trim(usrloc) ; if ( not fileexist(filcheck1) ) then do; jbstatus="F" ; Put "XBstart: Foute invoer:" jbid " code/source not existing: " filcheck1 "-- " curdatetim " --" ; end; if ( not fileexist(filcheck2) ) then do; jbstatus="F" ; Put "XBstart: Foute invoer:" jbid " output/logging locations not existing: " filcheck2 "-- " curdatetim " --" ; end; end; if ( jbstatus= " ") then do; if ( jbid = " " ) then do; jbid="AdHoc_"||put( rand('UNIFORM') * 9999 ,Z4.-L ) ; Put "WR jbinit: Correction jbid (empty) to be able finding it again set as:" jbid "-- " curdatetim " --" ; end; if ( jbwinend < curdatetim & jbwinend ne . ) then do; JBstatus="T";put "WR jbinit: " jbid "Timed out: ending time is before current moment " jbwinend " " curdatetim ; end ; end; seljobsubmit = 1 ; /* aanduiding alles ok behalve afhankelijkheden */ selnodelaymsg = mod (&xbstart_cntr,&xbwaitmsg) ; if ( jbstatus in (" ","W","w") ) then do; if ( jbwinstart > curdatetim & jbwinstart ne . ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount " Start moment not achieved " jbwinstart " - " curdatetim ; end; end ; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* validate tables - SAS datasets */ do i=1 to dim(trgdsn); IF ( trgdsn{i} ne "" ) THEN do ; if ( not exist(trgdsn{i}) ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount " Prereq table:" trgdsn{i} " does noet exist yet. " curdatetim ; end; end; end; end; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* validate tables - SAS datasets */ do i=1 to dim(blkdsn); IF ( blkdsn{i} ne "" ) THEN do ; if ( exist(blkdsn{i}) ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount " Blocking table:" blkdsn{i} " still existing. " curdatetim ; end; end; end; end; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* valideer files */ do i=1 to dim(trgfil); IF ( trgfil{i} ne "" ) THEN do ; if ( not fileexist(trgfil{i}) ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount " waiting for file:" trgfil{i} " does not exist yet. " curdatetim ; end; end; end; end; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* valideer files */ do i=1 to dim(blkfil); IF ( blkfil{i} ne "" ) THEN do ; if ( fileexist(blkfil{i}) ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount "Blocking file:" blkfil{i} " does still exist. " curdatetim ; end; end; end; end; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* valideer voorgaande jobs */ do i=1 to dim(trgjb); IF ( trgjb{i} ne "" ) THEN do ; dsnamtst="_WRjbloc.&jbdata._RDY (where=( jbid = '" || trim(put(trgjb{i} ,$16.)) || "' and jbstatus in('E','e') ) )" ; dsid=open(dsnamtst ) ; if (dsid = 0 ) then do; errmsg=sysmsg() ; put errmsg ; end; else do; rcdsid=fetch(dsid) ; /* no job status found as ready */ if ( rcdsid ne 0 ) then do; seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount "Prereq dependant job:" trgjb{i} " has not run yet " curdatetim ; end; end; end; rcdsid=close(dsid) ; end; end; end; if ( jbstatus in (" ","W","w") & seljobsubmit = 1 ) then do; /* validate previous jobs */ do i=1 to dim(blkjb); IF ( blkjb{i} ne "" ) THEN do ; dsnamtst="_WRjbloc.&jbdata._RDY (where=( jbid = '" || trim(put(blkjb{i} ,$16.)) || "' and jbstatus in('E','e') ) )" ; dsid=open(dsnamtst ) ; if (dsid = 0 ) then do; errmsg=sysmsg() ; put errmsg ; end; else do; rcdsid=fetch(dsid) ; if ( rcdsid = 0 ) then do; /* there are records, the status of the job is that an is dat de status blok */ seljobsubmit = 0 ; IF ( selnodelaymsg = 0 ) then do; put "WR jbinit: " jbid " Delay:" waitcount "Blocking job:" blkjb{i} " has already run - replan? " curdatetim ; end; end; end; rcdsid=close(dsid) ; end; end; end; if ( seljobsubmit = 1 ) Then do; if ( jbstatus in("W","w") ) then jbstatus=" " ; end; else do; if ( jbstatus = " " ) then do; jbstatus="W" ; waitcount=1 ; end ; else waitcount=waitcount + 1 ; dsnamtst="&bdapploc/&jbloc/"||trim(jbid)||"_NoWait" ; if (fileexist(dsnamtst) ) then do; JBstatus=" "; Put "WR jbinit: jbid " jbid " Wait condition manual bypassed signal by a dedicated filename. " curdatetim " --" ; rcdsid=filename("jbstprst",dsnamtst); rcdsid=fdelete("jbstprst"); rcdsid=filename("jbstprst"); end; end; if ( jbstatus= " " ) then do; if ( source ne " " ) then do; JBstatus="I"; jbrun_init = curdatetim ; submitstring='%xbatch(source='||trim(source)||",srcloc="||trim(srcloc)||",usrloc="||trim(usrloc)||",jbloc=&jbloc,jbid="||trim(jbid)||",print="||trim(print)||",sasopt="||trim(sasopt)||" ) ;" ; put submitstring; Call execute(submitstring) ; end; if ( source = " " & jbwintype ne " " ) then do; JBstatus="E"; jbrun_init = curdatetim ; /* no coded execution. A trigger allowing calendar adjustment */ put "WR jbinit: " jbid " =Completed= status=E, goal settin in time-shift" jbwintype " -- " curdatetim ; end; end; run;