Suspend a Job

Scenario Overview

This guide shows how to suspend CNC server jobs, useful for pausing tasks, addressing errors, or investigating issues.

Prerequisites

Before running, get an access token (‘Getting Started’), configure cnc-api-common.sh, and check input/output directories.

Retrieve Devices with a Specific Collection Status

Run the script suspend_job.sh from the example directory to suspend specific inventory job by providing the job name from the list.

cd cnc-inventory-api-examples;./suspend_job.sh

Script Details

#!/bin/bash
. ./cnc-api-common.sh

suspend_job() {
    # assume cnc jwt is obtained prior to invoking this method by executing get-cnc-jwt.sh script
    # read from jwt file and export it as AUTH_TOKEN_HDR
     export_jwt
    
    # STEP 1 :  Retrieve all the job specifications on the server.
    # STEP 2 :  At the input prompt, enter the job name and job type (in the format jobName:jobType) for the job you want to suspend.
    # STEP 3 :  Trigger suspendJob API.
    # STEP 4 :  Wait for 10 seconds, retrieve the updated job specifications, and copy them to the CNC_API_OUTPUT file.

    echo -e "\n\nGet details of all the jobs on the server: \n"	
    retrieve_job_specifications

    echo -e "\nEnter the job you want to suspend in the format jobName:jobType(Ex. Switch Inventory:Inventory):"
    read job_name

    CNC_API_INPUT="$PRJ/input/suspend_job.json"  
    echo "$job_name" > $CNC_API_INPUT
    
    CNC_API_URL=$CNC_INVENTORY_JOB_API_CTX/suspendJob
    CNC_API_OUTPUT="$PRJ/output/suspend_job.json"
    http_post $CNC_API_URL @$CNC_API_INPUT $CNC_API_OUTPUT
    
    echo -e "\n Waiting 10sec.."
    sleep 10
    retrieve_job_specifications
    echo -e "\n\nUpdated Job Specifications copied to $JOB_SPECS_OUTPUT\n" 
}
suspend_job