Automic Workload Automation

 View Only
  • 1.  Converting th script to automic script elements

    Posted 17 days ago

    Hi Team,

    we are trying to auto-restart a job when it fails due to some reasons, we have one script given below

    $JobName = "YOUR_JOB_NAME"

    $MaxRestartAttempts = 3

    $RestartAttempts = 0

     

    :LOOP

      $JOB_STATUS = JOB_GET_STATUS("$JobName")

      IF $JOB_STATUS = "FAILED" THEN (

        IF $RestartAttempts < $MaxRestartAttempts THEN (

          RESTART_UC_OBJECT("JOBS.JOBS", $JOB_RESULT_NUMBER, "", "NO_FLAGS")

          $RestartAttempts = $RestartAttempts + 1

          GO_TO :LOOP

        ) ELSE (

          PRINT "Job failed to restart after $MaxRestartAttempts attempts. Exiting."

          EXIT

        )

      )

    END

    can you please modify the script for Automic?

    Thanks,

    Abhishek



  • 2.  RE: Converting th script to automic script elements

    Posted 17 days ago

    Hello Abhishek Nayak,

    translate only the script in automic scripting language will not work. To get a useable script some use case informations could helpful.

    1. Do you want that the job is restart it self if it fail, or do you need to control another Job. 
    2. Do you wan't to embed this solution into a workflow. Within an workflow there are some other solutions conceivable.
    3. Do you need the restart function or is an ACTIVATE_UC_OBJECT also possible.

    The Boundary contitions decide how a useful solution look. 

    Best regards

    Andrzej Golaszewski




  • 3.  RE: Converting th script to automic script elements

    Posted 16 days ago

    Hi Andrzej,

    Thanks for your response on this matter,

     as per your above questions:

    1. what we actually want is when the job got failed due to some reasons says the agent offline , or it got ended not ok or aborted it should start by itself within the defined time interval.
    2. yeah if its possible we want to include the the script workflow or we can include it by using jobi within the jobs also . 
    3. if possible please provide us the both it will be helpful , if the i am not wrong activate uc object is a script element right if we use this then we need the help of count may be , if possible also tell us the difference between these two.

    thanks,

    Abhishek




  • 4.  RE: Converting th script to automic script elements

    Posted 16 days ago

    Here is some code I whipped up. This is based on code we use to automatically restart objects (ours is more complicated). I did use RESTART_UC_OBJECT instead of ACTIVATE_UC_OBJECT. This does require your object to be in a JOBP object.

    This might not be exactly what you are looking for, but it does work to restart an object.

    !So we can get the published value
    :SET &WF_RUNID# = SYS_ACT_TOP_NR()
    :SET &RCOUNTER# = GET_PUBLISHED_VALUE(&WF_RUNID#, RCOUNTER#)
    !if its not already set we need to set to 0 otherwise adding results in error
    :IF &RCOUNTER# = ' '
    :  SET &RCOUNTER# = 0
    :ENDIF
    !define restart params
    :SET &MAXRESTARTATTEMPTS# = 3
    :SET &WAITTIME# = 20
    !get the status of this object
    :SET &OBJSTATUS# = GET_UC_OBJECT_STATUS(,&$RESTART_RUNID#,STATUS)
    !if failed
    :IF &OBJSTATUS# = '1800'
    :  SWITCH 'Y'
    :    CASE &RCOUNTER# <= &MAXRESTARTATTEMPTS#
    !      Wait because instant restarts and bad code could be infinite loop
    :      WAIT &WAITTIME#
    :      PRINT 'Restarting Object'
    :      SET &RCOUNTER# = &RCOUNTER# + 1
    !      publish so we can get on the next restart
    :      PUBLISH &RCOUNTER# , , 'TOP'
    :      SET &RET# = RESTART_UC_OBJECT(&$NAME#,LAST)
    :    OTHER &RCOUNTER# > &MAXRESTARTATTEMPTS#
    !      So other jobs after this can restart, or if manually restarting this object    
    :      SET &RCOUNTER# = 0
    :      PUBLISH &RCOUNTER# , , 'TOP'
    :      PRINT 'Job failed to restart after (&MAXRESTARTATTEMPTS#) attempts. Exiting.'
    :  ENDSWITCH
    :ENDIF




  • 5.  RE: Converting th script to automic script elements

    Posted 15 days ago

    Hello Abhishek Nayak,

    in addition to the post of Eric Lontz i've another approach. This can be used if Jobs are not running within a workflow. From View of System it is not a clean restart of a job, more try 3 times to run the job.  Put the following on the POST_PROCESSING tab of your job.

    : SET &THIS_JOB_RUNID#=SYS_ACT_RESTART_ME_NR()
    : PRINT "My RunId ist &THIS_JOB_RUNID#"
    : SET &THIS_JOB_NAME#=SYS_ACT_ME_NAME()
    : SET &JESU# = GET_UC_OBJECT_STATUS(&THIS_JOB_RUNID#)
    : SET &MAX_RESTART#=3
    :SET &PN# = SYS_ACT_PARENT_NAME(ACT)

    ! If the activator of the job is not himself, job run's for the first time.

    : IF &PN# <> '&THIS_JOB_NAME#'
    :    P "This job is a first run job"
    :    SET &R_COUNT# = 0
    :    PUT_VAR AUTORESTART.TABLE,&THIS_JOB_NAME#,&R_COUNT#,&THIS_JOB_RUNID#
    : ELSE
    :    P "This job is a restarted job"
    :    SET &ORIGIN_RUN_ID#=GET_VAR(AUTORESTART.TABLE,&THIS_JOB_NAME#,"2")
    :    SET &R_COUNT#=GET_VAR(AUTORESTART.TABLE,&THIS_JOB_NAME#,"1")
    : ENDIF
    :If &R_COUNT# <= &MAX_RESTART#
    :    SWITCH "Y"
    :    CASE &JESU# BETWEEN 1900 AND 1999
    :      P "No Restart necessary"
    :      DELETE_VAR AUTORESTART.TABLE,"*"
    :    OTHER
    :      P "Job fail, Restart necessary"
    :      WAIT 1
    :      SET &R_COUNT#=&R_COUNT#+1
    :        PUT_VAR_COL AUTORESTART.TABLE,&THIS_JOB_NAME#,"1",&R_COUNT#
    :        SET &RESTART#=ACTIVATE_UC_OBJECT(&THIS_JOB_NAME#):
    :    ENDSWITCH
    !:ELSE
    :     P "Max Anzahl Rerun erreich, Job Exit"
    :     DELETE_VAR AUTORESTART.TABLE,"*"
    :ENDIF

    It is only a proof of concept, but it will do the job. In production systems i would be very cautious working with this method. Little mistakes can lead to endless job loops. 

    The Automation Engine itself has some good working tools for your use case . In a Workflow you can easily do this in workflow editor. It is a much more safe method to implement this behavior. 

    1. In the Workflow editor click on the job/object you want to restart.
    2. Select tab "Postconditions"
    3. Click on "Add Postconditions"

      AddPostCondition
    4. Insert Condition "CHECK STATUS"
    5. In the IF branch choose "status" = ANY_ABEND
    6. Add User defined action to the "IF" branch
    7. Value1 = &$RESTART_COUNT# (System Variable), CONDITION = "<" , Value2=3 ( Your Max Restart Count)
    8. Add from tab "Finally" "RESTART_TASK" select wait time you wan't to restart your task
    9. Open the menu for FINALLY task an select "Repeat processing"
    10. On the ELSE branch of "AND IF" you can put a mail call or something you want to do to get informed, inform other users or depeartments. 

    After you finish you're postcondition look something like that:

    Instead of using numbers, you can use predefined Variables. In my opinion the much more cleaner and more automic like method. 
    Hope that helps, best regards
    Andrzej Golaszewski