Wrapper around task result data. When a task is executed, an instance of ``Result`` is returned to provide access to the return value. To retrieve the task's result value, you can simply call the wrapper:: @huey.task() def my_task(a, b): return a + b
| 1182 | |
| 1183 | |
| 1184 | class Result(object): |
| 1185 | """ |
| 1186 | Wrapper around task result data. When a task is executed, an instance of |
| 1187 | ``Result`` is returned to provide access to the return value. |
| 1188 | |
| 1189 | To retrieve the task's result value, you can simply call the wrapper:: |
| 1190 | |
| 1191 | @huey.task() |
| 1192 | def my_task(a, b): |
| 1193 | return a + b |
| 1194 | |
| 1195 | result = my_task(1, 2) |
| 1196 | |
| 1197 | # After a moment, when the consumer has executed the task and put |
| 1198 | # the result in the result storage, we can retrieve the value. |
| 1199 | print result() # Prints 3 |
| 1200 | |
| 1201 | # If you want to block until the result is ready, you can pass |
| 1202 | # blocking=True. We'll also specify a 4 second timeout so we don't |
| 1203 | # block forever if the consumer goes down: |
| 1204 | result2 = my_task(2, 3) |
| 1205 | print(result(blocking=True, timeout=4)) |
| 1206 | """ |
| 1207 | def __init__(self, huey, task): |
| 1208 | self.huey = huey |
| 1209 | self.task = task |
| 1210 | self.revoke_id = task.revoke_id |
| 1211 | self._result = EmptyData |
| 1212 | |
| 1213 | def __repr__(self): |
| 1214 | return '<Result: task %s>' % self.id |
| 1215 | |
| 1216 | @property |
| 1217 | def id(self): |
| 1218 | return self.task.id |
| 1219 | |
| 1220 | def __call__(self, *args, **kwargs): |
| 1221 | return self.get(*args, **kwargs) |
| 1222 | |
| 1223 | def is_ready(self): |
| 1224 | return self._get() is not EmptyData |
| 1225 | |
| 1226 | def _get(self, preserve=False): |
| 1227 | task_id = self.id |
| 1228 | if self._result is EmptyData: |
| 1229 | res = self.huey.get_raw(task_id, peek=preserve) |
| 1230 | |
| 1231 | if res is not EmptyData: |
| 1232 | self._result = self.huey.serializer.deserialize(res) |
| 1233 | return self._result |
| 1234 | else: |
| 1235 | return res |
| 1236 | else: |
| 1237 | return self._result |
| 1238 | |
| 1239 | def get_raw_result(self, blocking=False, timeout=None, backoff=1.15, |
| 1240 | max_delay=1.0, revoke_on_timeout=False, preserve=False): |
| 1241 | res = self._get(preserve) |
no outgoing calls
no test coverage detected