(
self,
queue: str,
tasks: List[Task],
log: BoundLogger,
locks: Collection[Lock],
queue_lock: Optional[Semaphore],
)
| 404 | log.exception("task heartbeat failed") |
| 405 | |
| 406 | def execute( |
| 407 | self, |
| 408 | queue: str, |
| 409 | tasks: List[Task], |
| 410 | log: BoundLogger, |
| 411 | locks: Collection[Lock], |
| 412 | queue_lock: Optional[Semaphore], |
| 413 | ) -> bool: |
| 414 | assert tasks |
| 415 | |
| 416 | # Run heartbeat thread. |
| 417 | all_task_ids = {task.id for task in tasks} |
| 418 | stop_event = threading.Event() |
| 419 | heartbeat_thread = threading.Thread( |
| 420 | target=self._periodic_heartbeat, |
| 421 | kwargs={ |
| 422 | "queue": queue, |
| 423 | "task_ids": all_task_ids, |
| 424 | "log": log, |
| 425 | "locks": locks, |
| 426 | "queue_lock": queue_lock, |
| 427 | "stop_event": stop_event, |
| 428 | }, |
| 429 | ) |
| 430 | heartbeat_thread.start() |
| 431 | |
| 432 | serialized_task_func = tasks[0].serialized_func |
| 433 | for task in tasks: |
| 434 | log.info( |
| 435 | "processing", |
| 436 | func=serialized_task_func, |
| 437 | task_id=task.id, |
| 438 | params={"args": task.args, "kwargs": task.kwargs}, |
| 439 | ) |
| 440 | |
| 441 | # Run the tasks. |
| 442 | try: |
| 443 | result = self.execute_tasks(tasks, log) |
| 444 | # Always stop the heartbeat thread -- even in case of an unhandled |
| 445 | # exception after running the task code, or when an unhandled |
| 446 | # BaseException is raised from within the task. |
| 447 | finally: |
| 448 | stop_event.set() |
| 449 | heartbeat_thread.join() |
| 450 | |
| 451 | return result |
nothing calls this directly
no test coverage detected