def nextChainableJobGraph(jobGraph, jobStore):
    """Returns the next chainable jobGraph after this jobGraph if one
    exists, or None if the chain must terminate.
    """
    #If no more jobs to run or services not finished, quit
    if len(jobGraph.stack) == 0 or len(jobGraph.services) > 0 or jobGraph.checkpoint != None:
        logger.debug("Stopping running chain of jobs: length of stack: %s, services: %s, checkpoint: %s",
                     len(jobGraph.stack), len(jobGraph.services), jobGraph.checkpoint != None)
        return None

    #Get the next set of jobs to run
    jobs = jobGraph.stack[-1]
    assert len(jobs) > 0

    #If there are 2 or more jobs to run in parallel we quit
    if len(jobs) >= 2:
        logger.debug("No more jobs can run in series by this worker,"
                    " it's got %i children", len(jobs)-1)
        return None

    #We check the requirements of the jobGraph to see if we can run it
    #within the current worker
    successorJobNode = jobs[0]
    if successorJobNode.memory > jobGraph.memory:
        logger.debug("We need more memory for the next job, so finishing")
        return None
    if successorJobNode.cores > jobGraph.cores:
        logger.debug("We need more cores for the next job, so finishing")
        return None
    if successorJobNode.disk > jobGraph.disk:
        logger.debug("We need more disk for the next job, so finishing")
        return None
    if successorJobNode.preemptable != jobGraph.preemptable:
        logger.debug("Preemptability is different for the next job, returning to the leader")
        return None
    if successorJobNode.predecessorNumber > 1:
        logger.debug("The jobGraph has multiple predecessors, we must return to the leader.")
        return None

    # Load the successor jobGraph
    successorJobGraph = jobStore.load(successorJobNode.jobStoreID)

    # Somewhat ugly, but check if job is a checkpoint job and quit if
    # so
    if successorJobGraph.command.startswith("_toil "):
        #Load the job
        successorJob = Job._loadJob(successorJobGraph.command, jobStore)

        # Check it is not a checkpoint
        if successorJob.checkpoint:
            logger.debug("Next job is checkpoint, so finishing")
            return None

    # Made it through! This job is chainable.
    return successorJobGraph
def nextChainableJobGraph ( jobGraph , jobStore ) : if len ( jobGraph . stack ) == 0 or len ( jobGraph . services ) > 0 or jobGraph . checkpoint != None : logger . debug ( "Stopping running chain of jobs: length of stack: %s, services: %s, checkpoint: %s" , len ( jobGraph . stack ) , len ( jobGraph . services ) , jobGraph . checkpoint != None ) return None jobs = jobGraph . stack [ - 1 ] assert len ( jobs ) > 0 if len ( jobs ) >= 2 : logger . debug ( "No more jobs can run in series by this worker," " it's got %i children" , len ( jobs ) - 1 ) return None successorJobNode = jobs [ 0 ] if successorJobNode . memory > jobGraph . memory : logger . debug ( "We need more memory for the next job, so finishing" ) return None if successorJobNode . cores > jobGraph . cores : logger . debug ( "We need more cores for the next job, so finishing" ) return None if successorJobNode . disk > jobGraph . disk : logger . debug ( "We need more disk for the next job, so finishing" ) return None if successorJobNode . preemptable != jobGraph . preemptable : logger . debug ( "Preemptability is different for the next job, returning to the leader" ) return None if successorJobNode . predecessorNumber > 1 : logger . debug ( "The jobGraph has multiple predecessors, we must return to the leader." ) return None successorJobGraph = jobStore . load ( successorJobNode . jobStoreID ) if successorJobGraph . command . startswith ( "_toil " ) : successorJob = Job . _loadJob ( successorJobGraph . command , jobStore ) if successorJob . checkpoint : logger . debug ( "Next job is checkpoint, so finishing" ) return None return successorJobGraph
Returns the next chainable jobGraph after this jobGraph if one
    exists, or None if the chain must terminate.