This is somethin we currently use in one of our customer environements.
You can adjust it as per your requirements or remove some of the comments.
We are using it as include (JOBI) in whichever object is required.
We decided to keep the values in a static VARA object and perform the restart with 5minutes inbetween executions.
P.S. JOBI.MONITORING is our include for the alerting, you can disregard that line.
:SET &THISJOBNAME# = SYS_ACT_ME_NAME()
:SET &THISJOBNR# = SYS_ACT_RESTART_ME_NR()
:SET &THISSTATUS# = GET_UC_OBJECT_STATUS('JOBS', '&THISJOBNR#', 'STATUS')
:SET &THISTIME# = SYS_TIME('HH:MM:SS')
:SET &THISDATE# = SYS_DATE('TT.MM.JJJJ')
:SET &VALUE# = 1
:SET &VALUE# = FORMAT(&VALUE#)
:SET &VALUE2# = 3
:SET &VALUE2# = FORMAT(&VALUE2#)
! Check if status is ENDED_OKAY or ENDED_NOTOK
:IF &THISSTATUS# = '1900' or 'ENDED_OK'
: SET &THISSTATUS# = 'ENDED_OK'
: p "&THISSTATUS#"
:ELSE
: SET &THISSTATUS# = 'ENDED_NOTOK'
: p "&THISSTATUS#"
:ENDIF
! Print Execution Information
:PRINT "Job name: &THISJOBNAME#"
:PRINT "Job RunID: &THISJOBNR#"
:PRINT "Status of the job: &THISSTATUS#"
:PRINT "Time of End: &THISTIME# &THISDATE#"
! If the status is ENDED_NOTOK add 1 to the variable and rerun after 5 minutes.
! If there is already an entry for the job the monitoring include will do its magic
:IF &THISSTATUS# = 'ENDED_NOTOK'
: S &TRG1# = GET_VAR(VARA.AUTO_RERUN_X3, &THISJOBNAME#, 1)
: IF &TRG1# = ''
: P "First Failure of the job.Rerunning after 5 minutes."
: PUT VARA.AUTO_RERUN_X3, &THISJOBNAME#, &VALUE#, &VALUE#, &THISDATE#, &THISTIME#
: WAIT 300
: SET &RERUNNAME# = SYS_ACT_ME_NAME()
: SET &RERUNRET# = RESTART_UC_OBJECT (&THISJOBNAME#,LAST)
: PRINT '&RERUNNAME# restarted.'
: ELSE
: IF &TRG1# < &VALUE2#
: S &TRG1# = FORMAT(&TRG1#)
: S &TRG1# = &TRG1# + 1
: S &TRG1# = FORMAT(&TRG1#)
: PUT_VAR_COL VARA.AUTO_RERUN_X3, &THISJOBNAME#, 1, &TRG1#
: P "This will be the &TRG1# rerun of the job.Rerunning after 5 minutes."
: WAIT 300
: SET &RERUNNAME# = SYS_ACT_ME_NAME()
: SET &RERUNRET# = RESTART_UC_OBJECT (&THISJOBNAME#,LAST)
: PRINT '&RERUNNAME# restarted.'
:ELSE
: P "The &TRG1# rerun of the job has failed. Taking appropriate action."
: INC JOBI.MONITORING,NOFOUND=IGNORE
:IF &TRG1# = 3
: DELETE_VAR VARA.AUTO_RERUN_X3, &THISJOBNAME#
:ENDIF
: ENDIF
: ENDIF
: ENDIF
! If the status is ENDED_OK, the entry will be deleted.
:IF &THISSTATUS# = 'ENDED_OK'
: p "Deleting Variable Entry"
: DELETE_VAR VARA.AUTO_RERUN_X3, &THISJOBNAME#
:ENDIF
Original Message:
Sent: 01-20-2016 12:43 PM
From: Anon Anon
Subject: Script in object to restart itself 3 times than fail
HI All, has anyone created a restart of an object via script? I am trying to write a script that will restart itself 3 times when it fails and then abend after three. I know I can do this via the result tab in task properties, but we have hundreds of jobplans that this one job runs in and we don't want to go through them all and set this parameter. Please let me know if anyone has scripted this before. thank