/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code usage Note: This program xwr_jbstat is included by xwr_start Filename _WRCode. Notes: - _WRjbloc (libref) is the location for all control data during the polling. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* * * xwr_jbstat Verify what jobs are ready and which ones shoud run. * * * */ /* * * Checking status running and should run jobs: * * * */ /* * * - Job should started by notifying a created file (20 seconds response) * * * */ /* * * - Filename existance (true/false) * * * */ /* * * - table existance (true/false) * * * */ /* * * - bypass conditions wait for a job when a dedicate filename exists * * * */ /* * * Mail alerts when mail is defined. * * * */ filename outbox email type="text/html"; data _WRjbloc.&jbdata ( drop=curdatetim bdrun_nobs dsid rcdsid errmsg dsnamtst ) _WRjbloc.&jbdata._RDY (keep=jbid jbstatus jbbron jbwinstart jbwinend source jbid_pid jbid_sascc jbrun_start jbrun_end bufno=8 bufsize=32k) ; set _WRjbloc.&jbdata end=end ; file print notitles; length errmsg $80 dsnamtst $255 ; curdatetim=datetime(); format curdatetim datetime. ; if ( jbstatus in("A","a","T","t","F","f") ) then do ; /* reset abend - timeout by using logistic file */ dsnamtst="&bdapploc/&jbloc/"||trim(jbid)||"_Reset" ; if (fileexist(dsnamtst) ) then do; JBstatus="I"; Put "XBstart: jbid " jbid " Abort action manual repaired? Restart as were job restarted." curdatetim " --" ; rcdsid=filename("jbstprst",dsnamtst); rcdsid=fdelete("jbstprst"); rcdsid=filename("jbstprst"); end; dsnamtst="&bdapploc/&jbloc/"||trim(jbid)||"_Complete" ; if (fileexist(dsnamtst) ) then do; JBstatus="E"; Put "XBstart: jbid " jbid " Abort actie manual set as ready-completed." curdatetim " --" ; rcdsid=filename("jbstprst",dsnamtst); rcdsid=fdelete("jbstprst"); rcdsid=filename("jbstprst"); end; end; IF ( jbstatus in("I","i") ) Then do ; /* job has submitted in jbinitm verify it is really running */ dsnamtst='_WRjbloc.'||trim(jbid)||'_pid' ; if ( exist(dsnamtst) ) then do; JBstatus="S"; dsid=open(dsnamtst) ; if (dsid = 0 ) then do; errmsg=sysmsg() ; put errmsg ; end; else do; rcdsid=fetch(dsid) ; jbid_pid =getvarn( dsid,varnum(dsid, 'jbid_pid' )) ; jbrun_start=getvarn( dsid,varnum(dsid, 'jbrun_start' )) ; rcdsid=close(dsid) ; end; Put "XBstart: jbid " jbid " start message found in " dsnamtst " process id:" jbid_pid " -- " jbrun_start " --" ; end; else do; JBstatus="A"; Put "XBstart: jbid " jbid " 20 seconds ago the sart command was given, nothing found it really did started: " dsnamtst / " Fatal problem is supposed to start jobn (Abort): " curdatetim " --" ; end; end; IF ( jbstatus in("S","s") ) then do ; /* job is running, check it has got finished, fast jobs status go I to S into E in one poll cycle */ dsid=open("_WRjbloc."||trim(jbid)||"_pid" ) ; if (dsid = 0 ) then do; errmsg=sysmsg() ; put errmsg ; end; else do; bdrun_nobs =attrn(dsid,'NOBS') ; if ( bdrun_nobs > 1 ) then do; JBstatus="E"; rcdsid=fetchobs(dsid,2) ; jbrun_end =getvarn( dsid,varnum(dsid, 'jbrun_end' )) ; jbid_sascc =getvarn( dsid,varnum(dsid, 'jbid_sascc' )) ; rcdsid=close(dsid) ; Put "XBstart: jbid " jbid " end gevonden (2e-record) pid:" jbid_pid " - SAS returncode:" jbid_sascc " - " jbrun_end " --" ; end; else do; rcdsid=close(dsid) ; dsnamtst="_WRjbloc.XB_running_pids (where=( pid = " || trim(put(jbid_pid,8.0)) || ") )" ; dsid=open(dsnamtst ) ; if (dsid = 0 ) then do; errmsg=sysmsg() ; put errmsg ; end; else do; rcdsid=fetch(dsid) ; if ( rcdsid ne 0 ) then do; JBstatus="A"; Put "XBstart: jbid " jbid "has started but is not being found as running process on the system wiht knowing pids " / " Fataal problem is supposed at running the SAS coding " source " (Abort): " curdatetim " --" ; end; rcdsid=close(dsid) ; end; end; end; end; file outbox ; Select ; /* notify using a mail when mail is defined */ When ( jbstatus in(" ","f","e","a","t","w","s") ) ; When ( jbstatus = "F" & index(notify_evnt,"F") > 0 ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control internal logic error: ' jbid ; put "This is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="f"; end; When ( jbstatus = "E" & index(notify_evnt,"E") > 0 ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control job has ended: ' jbid ; put "This is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="e"; end; When ( jbstatus = "A" & index(notify_evnt,"A") > 0 ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control job abnormal ended please act: ' jbid ; put "DThis is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="a"; end; When ( jbstatus = "T" & index(notify_evnt,"T") > 0 ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control job got out of defined time window, please act: ' jbid ; put "This is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="t"; end; When ( jbstatus = "W" & index(notify_evnt,"W") > 0 & curdatetim > ntfy_delay ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control job looks to get too late for starting: ' jbid ; put "This is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="w"; end; When ( jbstatus = "S" & index(notify_evnt,"S") > 0 & curdatetim > ntfy_running ) do ; put '!EM_FROM!' notify ; put '!EM_TO!' notify ; put '!EM_SUBJECT! WR Control job looks not to finishing in time: ' jbid ; put "This is an automatic generated message. &syshostname-&sysuserid" ; put "WR Control wrdataloc=&wrdataloc,jbloc=&jbloc,jbdata=&jbdata " ; put '!EM_SEND!' ; put '!EM_NEWMSG!' ; jbstatus="s"; end; Otherwise ; end; if ( end) then do; put '!EM_ABORT!'; end; output _WRjbloc.&jbdata ; /* All job information - rewrite */ output _WRjbloc.&jbdata._RDY ; /* Only trg lock test E or e saved, calendar adjustments E,e nothing else limited number of variables */ run;