Icon

    This is the documentation for for an older version of Qube.

    Documentation for the latest release is available here.

    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.

      File Modified
    File deletionCascade.py May 23, 2018 by John Burk

    deletionCascade.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    #!/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
    • No labels