Query task state. Arguments: id (str): See :attr:`id`. backend (Backend): See :attr:`backend`.
| 67 | |
| 68 | @Thenable.register |
| 69 | class AsyncResult(ResultBase): |
| 70 | class="st">"""Query task state. |
| 71 | |
| 72 | Arguments: |
| 73 | id (str): See :attr:`id`. |
| 74 | backend (Backend): See :attr:`backend`. |
| 75 | class="st">""" |
| 76 | |
| 77 | app = None |
| 78 | |
| 79 | class="cm">#: Error raised for timeouts. |
| 80 | TimeoutError = TimeoutError |
| 81 | |
| 82 | class="cm">#: The task's UUID. |
| 83 | id = None |
| 84 | |
| 85 | class="cm">#: The task result backend to use. |
| 86 | backend = None |
| 87 | |
| 88 | def __init__(self, id, backend=None, |
| 89 | task_name=None, class="cm"># deprecated |
| 90 | app=None, parent=None): |
| 91 | if id is None: |
| 92 | raise ValueError( |
| 93 | f&class="cm">#x27;AsyncResult requires valid id, not {type(id)}') |
| 94 | self.app = app_or_default(app or self.app) |
| 95 | self.id = id |
| 96 | self.backend = backend or self.app.backend |
| 97 | self.parent = parent |
| 98 | self.on_ready = promise(self._on_fulfilled, weak=True) |
| 99 | self._cache = None |
| 100 | self._ignored = False |
| 101 | |
| 102 | @property |
| 103 | def ignored(self): |
| 104 | class="st">""class="st">"If True, task result retrieval is disabled."class="st">"" |
| 105 | if hasattr(self, &class="cm">#x27;_ignored'): |
| 106 | return self._ignored |
| 107 | return False |
| 108 | |
| 109 | @ignored.setter |
| 110 | def ignored(self, value): |
| 111 | class="st">""class="st">"Enable/disable task result retrieval."class="st">"" |
| 112 | self._ignored = value |
| 113 | |
| 114 | def then(self, callback, on_error=None, weak=False): |
| 115 | self.backend.add_pending_result(self, weak=weak) |
| 116 | return self.on_ready.then(callback, on_error) |
| 117 | |
| 118 | def _on_fulfilled(self, result): |
| 119 | self.backend.remove_pending_result(self) |
| 120 | return result |
| 121 | |
| 122 | def as_tuple(self): |
| 123 | parent = self.parent |
| 124 | return (self.id, parent and parent.as_tuple()), None |
| 125 | |
| 126 | def as_list(self): |
no outgoing calls