Пример #1
0
    def WaitUntilComplete(self, poll_freq=2, timeout=None):
        """Poll until status is completed.

		If status is 'notStarted' or 'executing' continue polling.
		If status is 'succeeded' return
		Else raise exception

		poll_freq option is in seconds

		"""
        start_time = time.time()
        while not self.time_completed:
            status = self.Status()
            if status == 'executing':
                if not self.time_executed: self.time_executed = time.time()
                if clc.v2.time_utils.TimeoutExpired(start_time, timeout):
                    raise clc.RequestTimeoutException(
                        'Timeout waiting for Request: {0}'.format(self.id),
                        status)

            elif status == 'succeeded':
                self.time_completed = time.time()
            elif status in ("failed", "resumed" or "unknown"):
                # TODO - need to ID best reaction for resumed status (e.g. manual intervention)
                self.time_completed = time.time()
                raise (clc.CLCException(
                    "%s %s execution %s" %
                    (self.context_key, self.context_val, status)))

            time.sleep(poll_freq)
Пример #2
0
    def WaitUntilComplete(self, poll_freq=2, timeout=None):
        """Poll until all request objects have completed.

		If status is 'notStarted' or 'executing' continue polling.
		If status is 'succeeded' then success
		Else log as error

		poll_freq option is in seconds

		Returns an Int the number of unsuccessful requests.  This behavior is subject to change.

		>>> clc.v2.Server(alias='BTDI',id='WA1BTDIKRT02').PowerOn().WaitUntilComplete()
		0

		"""

        start_time = time.time()
        while len(self.requests):
            cur_requests = []
            for request in self.requests:
                status = request.Status()
                if status in ('notStarted', 'executing', 'resumed', 'queued',
                              'running'):
                    cur_requests.append(request)
                elif status == 'succeeded':
                    self.success_requests.append(request)
                elif status in ("failed", "unknown"):
                    self.error_requests.append(request)

            self.requests = cur_requests
            if self.requests > 0 and clc.v2.time_utils.TimeoutExpired(
                    start_time, timeout):
                raise clc.RequestTimeoutException(
                    'Timeout waiting for Requests: {0}'.format(
                        self.requests[0].id), self.requests[0].Status())

            time.sleep(
                poll_freq
            )  # alternately - sleep for the delta between start time and 2s

        # Is this the best approach?  Non-zero indicates some error.  Exception seems the wrong approach for
        # a partial failure
        return (len(self.error_requests))