Пример #1
0
def main():
    client = Client("cream_jobCancel", "1.0")
    client.createParser()
    client.readOptions()

    try:
        client.checkProxy()

        jobId = client.jobSubmit()

        client.debug("job id: " + jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)

    activeStates = ['PENDING', 'RUNNING', 'REALLY-RUNNING']
    terminalStates = ['DONE-OK', 'DONE-FAILED', 'ABORTED', 'CANCELLED']

    lastStatus=""

    while not lastStatus in activeStates:
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)
            client.debug("job status: " + lastStatus)

            if lastStatus in terminalStates:
                client.nagiosExit(client.UNKNOWN, "job already terminated")
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)

    try:       
        client.jobCancel(jobId)
    except Exception as ex:
        client.nagiosExit(client.UNKNOWN, ex)


    while not lastStatus == "CANCELLED":
        time.sleep(10)
        try:
            lastStatus, exitCode = client.jobStatus(jobId)

            client.debug("job status: " + lastStatus)
        except Exception as ex:
            client.nagiosExit(client.UNKNOWN, ex)

    try:
        client.jobPurge(jobId)
    except Exception as ex:
        client.debug("cannot purge the job")

    client.nagiosExit(client.OK, "OK: job cancelled")