In Vscode, I see this message from sonarlint and trying to figure out how to reduce the Cognitive Complexity of this function. Any assistance is appreciated in advance.
- restapi.py(86, 5): +1
 - restapi.py(86, 25): +1
 - restapi.py(89, 9): +2 (incl 1 for nesting)
 - restapi.py(91, 13): +3 (incl 2 for nesting)
 - restapi.py(91, 39): +1
 - restapi.py(93, 17): +4 (incl 3 for nesting)
 - restapi.py(95, 17): +1
 - restapi.py(97, 17): +1
 - restapi.py(100, 9): +1
 - restapi.py(104, 5): +1
 - restapi.py(105, 9): +2 (incl 1 for nesting)
 - restapi.py(107, 9): +1
 - restapi.py(111, 5): +1
 
Here is the code :
def job_status(service, headers, job_id):
    """This is my function to look at the Job Status"""
    job_endpoint = service + "Job/" + job_id
    completed = False
    maxtime = 600  # 10 min
    wait = 60
    loop = 0
    logger.info("Endpoint to load Job is : " + job_endpoint)
    while not completed and loop < maxtime:
        r = requests.get(job_endpoint, headers=headers)
        if r.status_code == 200:
            client_resp = r.json()
            if client_resp['jobs'][0] and client_resp['jobs'][0]['jobSummary']:
                current_status = client_resp['jobs'][0]['jobSummary']['status']
                if re.match('^Completed', current_status):
                    completed = True
                elif re.match('^(Kill|Failed|Interrupt)', current_status):  # already dead
                    break
                else:
                    sleep(wait)
                    loop += wait
        else:
            sleep(wait)
            loop += wait
    if not completed:
        if maxtime > loop:
            logger.info("Job failed with status " + current_status)
        else:
            logger.info("Job not completed in " + maxtime + "s with last status " + current_status)
        logger.info("failed")
        sys.exit(5)
    else:
        logger.info("executed successfully")
        sys.exit(0)
				
                        
I'd split this into two functions, one that does the looping you can early-return out of, and the other that deals with logging from there.