Am 18. März 2011 10:41 schrieb Iustin Pop <[email protected]>:
> --- a/lib/rapi/client.py
> +++ b/lib/rapi/client.py
> +  def WaitForJobCompletion(self, job_id, period=5, retries=-1):
> +    """Polls cluster for job status until completion.
> +
> +    Completion is defined as any of the following states:
> +      "error", "canceled", or "success"
> +
> +    @type job_id: int
> +    @param job_id: job id to watch

The job ID is a string.

> +    @type period: int
> +    @param period: how often to poll for status (optional, default 5s)
> +
> +    @type retries: int
> +    @param retries: how many time to poll before giving up
> +                    (optional, default -1 means unlimited)
> +
> +    @rtype: bool
> +    @return: True if job succeeded or False if failed/status timeout
> +    """

Missing empty line.

> +    while retries != 0:
> +      job_result = self.GetJobStatus(job_id)
> +      if not job_result or job_result["status"] in ("error", "canceled"):
> +        return False
> +      if job_result["status"] == "success":
> +        return True
> +      time.sleep(period)

Why don't you use WaitForJobChange and ignore the log?

> +      if retries > 0:
> +        retries -= 1
> +    return False
> +

Michael

Reply via email to