sendevent returns exit code 0 regardless of target job status
search cancel

sendevent returns exit code 0 regardless of target job status

book

Article ID: 441090

calendar_today

Updated On:

Products

Autosys Workload Automation

Issue/Introduction

An AutoSys job executing a sendevent command (e.g., JOB_ON_HOLD) completes with SUCCESS (exit code 0) even if the target job fails to change its state. Users require the job to FAIL if the target state is not achieved.

Environment

  • Product: AutoSys Workload Automation
  • Platform: Linux / Unix / Windows

Cause

The sendevent command is asynchronous by design. It returns a return code of 0 once the event is successfully queued in the AutoSys database. It does not wait for the Event Processor to pick up the event, nor does it verify if the event was successfully applied to the target job.

Resolution

To force a job to fail based on the target job's state, you must implement a validation step using autorep. This can be done via a wrapper script or an inline command block.

Implementation Steps

  1. Modify the job's command to run a script that sends the event and then validates the result.
  2. Include a brief sleep to allow the Event Processor time to process the database queue.
  3. Use autorep to check the status and explicitly exit 1 if the validation fails.

Example Script (Linux/Unix)

#!/bin/bash
TARGET_JOB="MY_TARGET_JOB"

# 1. Fire the event
sendevent -E JOB_ON_HOLD -J $TARGET_JOB

# 2. Pause to allow the Event Processor to catch up
sleep 5

# 3. Capture the current status using autorep
# The 6th column in 'autorep -q' typically contains the status code (e.g., OH for ON_HOLD)
STATUS=$(autorep -J $TARGET_JOB -q | grep $TARGET_JOB | awk '{print $6}')

# 4. Evaluate and exit accordingly
if [ "$STATUS" = "OH" ]; then
    echo "Success: $TARGET_JOB is now ON_HOLD."
    exit 0
else
    echo "Error: $TARGET_JOB is in status $STATUS instead of ON_HOLD."
    exit 1
fi