Пример #1
0
def blockOnTasks(options, tasks):
    maxTaskNameLen = tasks and max([len(t.name) for t in tasks]) or 0
    sleepTime = 1
    ##
    # Loop until all of the tasks are in state FAILED or COMPLETED
    while [
            t for t in tasks
            if t.state not in [task.TASK_FAILED, task.TASK_COMPLETED]
    ]:
        if showAnyMsg(options):
            if not options('general.no_print_polling'):
                commands.runSystem('clear')
                for t in tasks:
                    printTask(options, t, maxTaskNameLen)
        time.sleep(sleepTime)
        sleepTime = sleepTime < 30 and sleepTime * 2 or 30
        tasks = [
            loadTask(options('general.host'), options('general.name'), t.name)
            for t in tasks
        ]

    ##
    # If we are showing any messages then clear the screen because after this
    # the tasks will be printed out again
    if showAnyMsg(options) and not options('general.no_print_polling'):
        commands.runSystem('clear')

    return tasks
Пример #2
0
def blockOnTask(host, name, taskName, notifyF=logPrint, errorF=errorPrint):
    endStates = [task.TASK_FAILED, task.TASK_COMPLETED]
    state = None
    prevTime = None
    sleepTime = 1
    time.sleep(sleepTime)
    while state not in endStates:
        tsk = loadTask(host, name, taskName)
        state = tsk.state
        if prevTime is None:
            msgs = tsk.getMessages()
        else:
            msgs = tsk.getMessagesAfterTime(prevTime)
        prevTime = tsk.timestamp
        for m in msgs:
            if m['mtype'] == task.MSG_ERROR:
                errorF(m['text'])
            elif m['mtype'] == task.MSG_NOTIFICATION:
                notifyF(m['text'])
            elif logging.DEBUG and m['mtype'] == task.MSG_SILENT:
                debugPrint(lambda : m['text'])
        ##
        # Make this configurable
        if state not in endStates:
            sleepTime = sleepTime < 30 and sleepTime * 2 or 30
            time.sleep(sleepTime)

    return state
Пример #3
0
def blockOnTask(host, name, taskName, notifyF=logPrint, errorF=errorPrint):
    endStates = [task.TASK_FAILED, task.TASK_COMPLETED]
    state = None
    prevTime = None
    sleepTime = 1
    time.sleep(sleepTime)
    while state not in endStates:
        tsk = loadTask(host, name, taskName)
        state = tsk.state
        if prevTime is None:
            msgs = tsk.getMessages()
        else:
            msgs = tsk.getMessagesAfterTime(prevTime)
        prevTime = tsk.timestamp
        for m in msgs:
            if m['mtype'] == task.MSG_ERROR:
                errorF(m['text'])
            elif m['mtype'] == task.MSG_NOTIFICATION:
                notifyF(m['text'])
            elif logging.DEBUG and m['mtype'] == task.MSG_SILENT:
                debugPrint(lambda: m['text'])
        ##
        # Make this configurable
        if state not in endStates:
            sleepTime = sleepTime < 30 and sleepTime * 2 or 30
            time.sleep(sleepTime)

    return state
Пример #4
0
def main(options, tasks):
    if options('general.debug'):
        logging.DEBUG = True

    if not tasks:
        debugPrint(lambda: 'No task names provided, loading all from database')
        tasks = loadAllTasks(options('general.host'), options('general.name'))
    else:
        debugPrint(lambda: 'Task names provided, loading from database')
        tasks = [
            loadTask(options('general.host'), options('general.name'), t)
            for t in tasks
        ]

    if options('general.block'):
        debugPrint(lambda: 'Blocking until tasks finish or fail')
        tasks = blockOnTasks(options, tasks)

    if options('general.no_completed'):
        debugPrint(lambda: 'Removing any completed tasks')
        tasks = filter(lambda t: t.state != task.TASK_COMPLETED, tasks)

    ##
    # If there are tasks, find the largest, otherwise just return 0
    maxTaskNameLen = tasks and max([len(t.name) for t in tasks]) or 0
    printSpacing = False
    for t in tasks:
        if not printSpacing:
            printSpacing = True
        else:
            print
            print

        printTask(options, t, maxTaskNameLen)

    if options('general.exit_code'):
        debugPrint(
            lambda:
            'Exiting with non-zero state if any tasks are not in a completed state'
        )
        notCompleted = [t for t in tasks if t.state != task.TASK_COMPLETED]
        if notCompleted:
            return 1
        else:
            return 0

    return 0
Пример #5
0
def main(options, tasks):
    if options('general.debug'):
        logging.DEBUG = True

    if not tasks:
        debugPrint(lambda : 'No task names provided, loading all from database')
        tasks = loadAllTasks(options('general.host'), options('general.name'))
    else:
        debugPrint(lambda : 'Task names provided, loading from database')
        tasks = [loadTask(options('general.host'), options('general.name'), t)
                 for t in tasks]

    if options('general.block'):
        debugPrint(lambda : 'Blocking until tasks finish or fail')
        tasks = blockOnTasks(options, tasks)
        
    if options('general.no_completed'):
        debugPrint(lambda : 'Removing any completed tasks')
        tasks = filter(lambda t : t.state != task.TASK_COMPLETED, tasks)


    ##
    # If there are tasks, find the largest, otherwise just return 0
    maxTaskNameLen = tasks and max([len(t.name) for t in tasks]) or 0
    printSpacing = False
    for t in tasks:
        if not printSpacing:
            printSpacing = True
        else:
            print
            print

        printTask(options, t, maxTaskNameLen)

    if options('general.exit_code'):
        debugPrint(lambda : 'Exiting with non-zero state if any tasks are not in a completed state')
        notCompleted = [t for t in tasks if t.state != task.TASK_COMPLETED]
        if notCompleted:
            return 1
        else:
            return 0

    return 0
Пример #6
0
def blockOnTasks(options, tasks):
    maxTaskNameLen = tasks and max([len(t.name) for t in tasks]) or 0
    sleepTime = 1
    ##
    # Loop until all of the tasks are in state FAILED or COMPLETED
    while [t for t in tasks if t.state not in [task.TASK_FAILED, task.TASK_COMPLETED]]:
        if showAnyMsg(options):
            if not options('general.no_print_polling'):
                commands.runSystem('clear')
                for t in tasks:
                    printTask(options, t, maxTaskNameLen)
        time.sleep(sleepTime)
        sleepTime = sleepTime < 30 and sleepTime * 2 or 30
        tasks = [loadTask(options('general.host'), options('general.name'), t.name)
                 for t in tasks]

    ##
    # If we are showing any messages then clear the screen because after this
    # the tasks will be printed out again
    if showAnyMsg(options) and not options('general.no_print_polling'):
        commands.runSystem('clear')
        
    return tasks