Search code examples
batch-filescheduled-tasksautosys

Put an autosys job ON_ICE automatically depending on a calendar


I am working with a path of jobs on autosys that runs every night.

One of these jobs needs to run only on certain dates at the beginning of each month (usually the first 4 days but it can change depending on the business) so currently I'm putting said job ON_ICE or OFF_ICE manually and I'm looking to automate this.

I currently have 2 ideas but I'm stuck either way I choose.

Option 1 (the cleanest ?)

I would create a new job in between daily_job and monthly_job, called let's say calendar_check. this job would start a batch on my app serveur, checking the database of my app where the calendar is, and depending of the database check sending back to autosys the good command to put the next job ON or OFF_ICE.

My batch looks like this

%My_SQLPATH% -S %My_SQL_SERVER% -d %My_SQL_DB -h-1 -W -Q "SQL Query that returns 1 or 0 depending on the calendar in my application" output.txt
set /P bEndMonth= < output.txt
echo %bEndMonth%
del output.txt
IF %bEndMonth% == 0 (start "somthing i don't know what 'sendevent -j ON_ICE -e monthly_job'") ELSE (start "somthing i don't know what 'sendevent -e OFF_ICE -j monthly_job'")

That last line is what I don't know how to write or if it's even possible to get back to my autosys server and use the sendevent command.

Little diagram for clarity enter image description here

Option 2 (more messy but maybe easier)

I create 2 new jobs. One, on my path of jobs put monthly_job ON_ICE everyday. Another one, not on my path of jobs, reads an autosys calendar and runs only on the calendar dates to put monthly_job OFF_ICE. Downside is I must maintain another calender in autosys but it's minor.

But again I don't know the syntaxe for the jil to ask one job to put another job on or off ice.

Little diagram again for clarity option 2 diagram

Any help is welcome or any other idea on how i could implement this. Thank you !


Solution

  • For executing sendevent command in Autosys, the autosys cli package has to be installed, local variable to be declared and then login to the particular instance.

    This could be verified by the Scheduling Admin/Middleware team if any.

    If the days of the run at the start of the month is fixed, like first 5 days or first 5 working days, extended calendar can be considered.

    Alternative way: Since the condition to run/hold the job is based on the output of the SQL query from the database, we would use user defined exit code based on which the monthly job would trigger.

    Step1: Make a script that would fetch the SQL query output and based on it we can define user exit codes.

    LOGIN Database;
    EXEC SQL Query;
    IF %bEndMonth% == 0
        THEN exit 0;
    ELSE 
        exit 1;
    

    Generally if the job exit code is > than 0, it would trigger an alarm for job failure, if required to suppress this, add the following attribute to this job:

    max_exit_success:1
    

    Now the job would be marked as success incase the exit is 0 or 1. Considering the name of the job is Job_Cal_Check and is defined daily to run.

    Step 2: The monthly job/box would have no calendar and it would only trigger if the Job_Cal_Check job has exit 1. Add the following attribute

    condition: exitcode (Job_Cal_Check) = 1
    

    Edits: Fix Mis Run of successive jobs

    Create an intermediate job to sleep for x seconds, calculate this time +-2 or 3 seconds taken for the monthly job to start after completion of the Job_Cal_Check.

    The job flow would be:

    Non Monthly Job
    Previous Chain -> Job_Cal_Check -> Sleep_Job -> Followup_Jobs *(would wait only for Sleep_Job as the Monthly job would have completed status from the previous run)*
    
    Monthly Job
    Previous Chain -> Job_Cal_Check -> Sleep_Job + Monthly_Job *(both these jobs would we activated simultaneously)* -> Followup_Jobs *(would wait for both the jobs to complete)*
    

    Job attributes as follows:

    Sleep_Job:
    condition: success (Job_Cal_Check)
    
    Followup_Jobs
    condition: success (Sleep_Job) AND success(Monthly_Job)
    

    On days of Non monthly job, Followup_Jobs would only wait for the Sleep_Job to complete.

    On days of Monthly job, Followup_Jobs would first wait for the Sleep_Job to complete by this time the Montlhy_Job would have Activated/In Running/Completed and upon completion, the job flow would continue.

    Hope this helps, if anything more required do ask.