Internal helper to move a task from one state to another (e.g. from QUEUED to DELAYED). The "when" argument indicates the timestamp of the task in the new state. If no to_state is specified, the task will be simply removed from the original state. The "mode"
(
self,
from_state: Optional[str] = None,
to_state: Optional[str] = None,
when: Optional[float] = None,
mode: Optional[str] = None,
)
| 295 | return self._executions |
| 296 | |
| 297 | def _move( |
| 298 | self, |
| 299 | from_state: Optional[str] = None, |
| 300 | to_state: Optional[str] = None, |
| 301 | when: Optional[float] = None, |
| 302 | mode: Optional[str] = None, |
| 303 | ) -> None: |
| 304 | """ |
| 305 | Internal helper to move a task from one state to another (e.g. from |
| 306 | QUEUED to DELAYED). The "when" argument indicates the timestamp of the |
| 307 | task in the new state. If no to_state is specified, the task will be |
| 308 | simply removed from the original state. |
| 309 | |
| 310 | The "mode" param can be specified to define how the timestamp in the |
| 311 | new state should be updated and is passed to the ZADD Redis script (see |
| 312 | its documentation for details). |
| 313 | |
| 314 | Raises TaskNotFound if the task is not in the expected state or not in |
| 315 | the expected queue. |
| 316 | """ |
| 317 | |
| 318 | scripts = self.tiger.scripts |
| 319 | |
| 320 | from_state = from_state or self.state |
| 321 | queue = self.queue |
| 322 | |
| 323 | assert from_state |
| 324 | assert queue |
| 325 | |
| 326 | try: |
| 327 | scripts.move_task( |
| 328 | id=self.id, |
| 329 | queue=self.queue, |
| 330 | from_state=from_state, |
| 331 | to_state=to_state, |
| 332 | unique=self.unique, |
| 333 | when=when or time.time(), |
| 334 | mode=mode, |
| 335 | key_func=self.tiger._key, |
| 336 | publish_queued_tasks=self.tiger.config["PUBLISH_QUEUED_TASKS"], |
| 337 | ) |
| 338 | except redis.ResponseError as e: |
| 339 | if "<FAIL_IF_NOT_IN_ZSET>" in e.args[0]: |
| 340 | raise TaskNotFound( |
| 341 | 'Task {} not found in queue "{}" in state "{}".'.format( |
| 342 | self.id, queue, from_state |
| 343 | ) |
| 344 | ) |
| 345 | raise |
| 346 | else: |
| 347 | self._state = to_state |
| 348 | |
| 349 | def execute(self) -> None: |
| 350 | func = self.func |