Automic Workload Automation

  • 1.  Script in object to restart itself 3 times than fail

    Posted Jan 20, 2016 12:43 PM
    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


  • 2.  Script in object to restart itself 3 times than fail

    Posted Jan 20, 2016 01:22 PM
    I've always done this via workflow post-condition logic.  The system maintains a variable called &$RESTART_COUNT# to automatically count the number of restarts that have occurred during post-condition processing.  In your scenario I would wrap a new workflow around the script to hold the post-condition restart rules, and then change all references to the script to run this new workflow instead.  Then if you need to change the restart behaviors in the future, you would only need to change it in one place.

    Another way to look at the problem would be to triple the size of your script so it tries three times before failing.  This could be simplified by moving the script into an include, and do the following;

    :include MY.INCLUDE
    :if it failed
    :   include MY.INCLUDE
    :endif
    :if it failed
    :  include MY.INCLUDE
    :endif


  • 3.  Script in object to restart itself 3 times than fail

    Posted Jan 20, 2016 03:39 PM
    Yes, this is something that we routinely do for our jobs that execute with a Start type of a Group as under V8 there is only the Properties/Result tab and nothing in the actual object.  We place our code in the object's Post Process as a common Include.


  • 4.  Script in object to restart itself 3 times than fail

    Posted Jan 22, 2016 03:59 PM
    It's possible to restart a job from its post process script, but it's a little messy. You can use the restart_uc_object() function, but it will not allow you to restart the job you are calling it from because the reference runid will still be active. So, you'd have to instead activate a second script object to act as a proxy "restarter" after the original job ends. The restarter script would do the restart, using the runid of the original job as the reference runid, and then the workflow should pick up the restart's status for the task. The &$RESTART_COUNT# variable doesn't get updated for some reason when you do this, so you'd have to track that in a vara or something to get a limited number of attempts.

    Post conditions is really the cleanest way to do this, I wish you could use an "include" type reference there.

    If you don't need the reference runid, you could use activate_uc_object() instead, I'm guessing that's what Mark_Hadler_430 was refering to above, but I think you need it to get the workflow to see the new run.


  • 5.  Script in object to restart itself 3 times than fail

    Posted Feb 08, 2016 12:20 PM
    Hy Guys - thanks for all this info.  I was able to script it using the restart_uc_object in the post process, but I needed to build a variable first in the pre-process.  I create the variable when the job starts and then in the post add to that variable the restart count.  once I hit the max restarts I simply delete the variable object in the post process so its ready for the next run.  I had a tough time with the objects always creating a new run number so I could not use NR as an option.  Thanks again and I hope to discuss new issues with you in the future.

    Is there a page peeps can add there scripts to for others to use?  or is that propitiatory to each company?

    regards,

    Scott


  • 6.  RE: Script in object to restart itself 3 times than fail

    Posted Sep 15, 2020 05:45 AM
    Hello Expert , 

    We have similar kind of requirement and we used post condition tab to check job status using if else. But we have many jobs, some jobs needs to restart after 2 failure and some after 3-4 failure so we are thinking to use script with variable which will count restart. 

    Is it possible for you to share your script logic  ? 

    Please find attached our setup.
     

    Thanks in advance.  

    Regards,
    Viral


  • 7.  Re: Script in object to restart itself 3 times than fail

    Posted Apr 06, 2019 09:49 AM

    You can use the SYS_ACT_ME_NR to get the original runid of the object vs the SYS_ACT_RESTAR_ME_NR that is returning the runid of the active run of the object. With this, you can set your variable to use the index on the original runid and just update the restart count. Original run set it systematically to 0, following restart of the object will just add 1 to this value until reaching the limit you have set ....



  • 8.  RE: Script in object to restart itself 3 times than fail

    Posted Sep 15, 2020 02:24 PM
    Edited by Krum Ganev Sep 15, 2020 02:32 PM

    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


  • 9.  RE: Script in object to restart itself 3 times than fail

    Posted Sep 16, 2020 08:47 AM
    Thank you.