thanks for your response, the postcondition one that you have provided worked fine, but I am facing some issues with the script
I am getting an error for the &R_COUNT# variable, after increment it took the value as text type not in a number format , so can you please advise what can be modified exactly?
Original Message:
Sent: Mar 28, 2024 09:23 AM
From: Andrzej Golaszewski
Subject: Converting th script to automic script elements
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.
- In the Workflow editor click on the job/object you want to restart.
- Select tab "Postconditions"
- Click on "Add Postconditions"
- Insert Condition "CHECK STATUS"
- In the IF branch choose "status" = ANY_ABEND
- Add User defined action to the "IF" branch
- Value1 = &$RESTART_COUNT# (System Variable), CONDITION = "<" , Value2=3 ( Your Max Restart Count)
- Add from tab "Finally" "RESTART_TASK" select wait time you wan't to restart your task
- Open the menu for FINALLY task an select "Repeat processing"
- 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
Original Message:
Sent: Mar 27, 2024 06:06 AM
From: Abhishek Nayak
Subject: Converting th script to automic script elements
Hi Andrzej,
Thanks for your response on this matter,
as per your above questions:
- 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.
- yeah if its possible we want to include the the script workflow or we can include it by using jobi within the jobs also .
- 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
Original Message:
Sent: Mar 26, 2024 01:58 PM
From: Andrzej Golaszewski
Subject: Converting th script to automic script elements
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.
- Do you want that the job is restart it self if it fail, or do you need to control another Job.
- Do you wan't to embed this solution into a workflow. Within an workflow there are some other solutions conceivable.
- 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
Original Message:
Sent: Mar 26, 2024 07:08 AM
From: Abhishek Nayak
Subject: Converting th script to automic script elements
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