Wait for task and return its result. If the task raises an exception, this exception will be re-raised by :func:`wait_for`. Raises: celery.exceptions.TimeoutError: If `timeout` is not :const:`None`, and the operation takes longer
(self, task_id,
timeout=None, interval=0.5, no_ack=True, on_interval=None)
| 1121 | return result.maybe_throw(propagate=propagate, callback=callback) |
| 1122 | |
| 1123 | def wait_for(self, task_id, |
| 1124 | timeout=None, interval=0.5, no_ack=True, on_interval=None): |
| 1125 | """Wait for task and return its result. |
| 1126 | |
| 1127 | If the task raises an exception, this exception |
| 1128 | will be re-raised by :func:`wait_for`. |
| 1129 | |
| 1130 | Raises: |
| 1131 | celery.exceptions.TimeoutError: |
| 1132 | If `timeout` is not :const:`None`, and the operation |
| 1133 | takes longer than `timeout` seconds. |
| 1134 | """ |
| 1135 | self._ensure_not_eager() |
| 1136 | |
| 1137 | time_elapsed = 0.0 |
| 1138 | |
| 1139 | while 1: |
| 1140 | meta = self.get_task_meta(task_id) |
| 1141 | if meta['status'] in states.READY_STATES: |
| 1142 | return meta |
| 1143 | if on_interval: |
| 1144 | on_interval() |
| 1145 | if timeout is not None and time_elapsed >= timeout: |
| 1146 | raise TimeoutError('The operation timed out.') |
| 1147 | # avoid hammering the CPU checking status. Never sleep past the |
| 1148 | # deadline: with the sleep first, timeout=0 blocked for a whole |
| 1149 | # interval before giving up, and any timeout below interval |
| 1150 | # overshot to interval. |
| 1151 | nap = interval if timeout is None else min(interval, timeout - time_elapsed) |
| 1152 | time.sleep(nap) |
| 1153 | time_elapsed += nap |
| 1154 | |
| 1155 | def add_pending_result(self, result, weak=False): |
| 1156 | return result |
no test coverage detected