Versions Compared

    Key

    • This line was added.
    • This line was removed.
    • Formatting was changed.
    Comment: Migrated to Confluence 5.3

    deletionCascade.pyQube jobs can belong to a process group, which is normally how a group of jobs define their inter-dependencies.  These process groups can be viewed as a single set of jobs in ArtistView as a collapsed set of jobs, or in WranglerView's MetaJob panel, or   From many users' points of view, the entire process group is actually just one task, and they'd like to be able to kill or remove the entire process group as a single unit.

    This can be accomplished indirectly through the use of a callback attached to the first job in the process group, the pgrp leader.  This calback can accomplish the killing or removal of all other jobs in the pgrp when the leader is killed or removed.

    Attachments
    uploadfalse

    Code Block
    titledeletionCascade.py
    linenumberstrue
    languagepython
    #!/usr/bin/env python
    import qb
    
    task = []
    def newJob(name, status='blocked'):
        job = {
            'prototype': 'cmdline',
            'name': 'job %s' % name,
            'label': 'job %s' % name,
            'status': status,
            'package': {
                'cmdline': 'set'
            },
            'callbacks': []
        }
        return job
    jobA = newJob('A', 'pending')
    
    
    #=======================================
    # add the callback for job removal
    #=======================================
    cbRemoved = { 
        'language': 'python',
        'triggers': 'removed-job-self',
        'code': '''
    jobID = qb.jobid()
    for i in [x['id'] for x in qb.jobinfo("-pgrp", jobID) if x['id'] != jobID]:
        qb.remove(i)
    '''
        }
    jobA['callbacks'].append(cbRemoved)
    
    #=======================================
    # add the callback for job kill
    #=======================================
    cbKilled = { 
        'language': 'python',
        'triggers': 'killed-job-self',
        'code': '''
    jobID = qb.jobid()
    for i in [x['id'] for x in qb.jobinfo("-pgrp", jobID) if x['id'] != jobID]:
        qb.kill(i)
    '''
        }
    
    jobA['callbacks'].append(cbKilled)
    jobA['package']['cmdline'] = 'sleep 15'
    
    task.append(jobA)
    
    
    jobB = newJob('B')
    task.append(jobB)
    
    
    jobC = newJob('C')
    task.append(jobC)
    
    
    jobD = newJob('D')
    task.append(jobD)
    
    
    jobB['dependency'] = 'link-complete-jobA'
    jobC['dependency'] = 'link-complete-jobA'
    jobD['dependency'] = 'link-complete-jobA'
    
    
    for i in qb.submit(task):
        print '%(name)s: %(id)s' % i