コード例 #1
0
 def test_check_status(self):
     expected = 'RUNNING'
     api = Mock()
     api.get_job.return_value = {'status': expected}
     type(api).__name__ = 'QuantumInspireAPI'
     job_identifier = 1
     qi_job = QuantumInspireJob(api, job_identifier)
     actual = qi_job.check_status()
     self.assertEqual(expected, actual)
コード例 #2
0
    def _wait_for_completed_job(quantum_inspire_job: QuantumInspireJob, collect_max_tries: Optional[int],
                                sec_retry_delay: float = 0.5) -> bool:
        """ Holds the process and requests the job status until completed or when
            the maximum number of tries has been reached.

        Args:
            quantum_inspire_job: A job object.
            collect_max_tries: The maximum number of request tries.
            sec_retry_delay: The time delay in between job status checks in seconds.

        Returns:
            True if the job result could be collected else False.
        """
        attempts = itertools.count() if collect_max_tries is None else range(collect_max_tries)
        for _ in attempts:
            time.sleep(sec_retry_delay)
            if quantum_inspire_job.check_status() == 'COMPLETE':
                return True
        return False
コード例 #3
0
    def _wait_for_completed_job(quantum_inspire_job: QuantumInspireJob, collect_max_tries: Optional[int] = None,
                                sec_retry_delay: float = 0.5) -> Tuple[bool, str]:
        """ Delays the process and requests the job status. The waiting loop is broken when the job status is
            completed or cancelled, or when the maximum number of tries is set and has been reached.

        Args:
            quantum_inspire_job: A job object.
            collect_max_tries: The maximum number of times the job status is checked. When set, the value should be > 0.
                               When not set, the method waits until the job status is either completed or cancelled.
            sec_retry_delay: The time delay in between job status checks in seconds.

        Returns:
            True if the job result could be collected else False in hte first part of the tuple.
            The latter part of the tuple contains an (error)message.
        """
        attempts = itertools.count() if collect_max_tries is None else range(collect_max_tries)
        for _ in attempts:
            time.sleep(sec_retry_delay)
            status = quantum_inspire_job.check_status()
            if status == 'COMPLETE':
                return True, 'Job completed.'
            if status == 'CANCELLED':
                return False, 'Failed getting result: job cancelled.'
        return False, 'Failed getting result: timeout reached.'