MCPcopy Create free account
hub / github.com/closeio/tasktiger / _process_queue_tasks

Method _process_queue_tasks

tasktiger/worker.py:460–528  ·  view source on GitHub ↗

Process tasks in queue.

(
        self,
        queue: str,
        queue_lock: Optional[Semaphore],
        task_ids: Set[str],
        now: float,
        log: BoundLogger,
    )

Source from the content-addressed store, hash-verified

458 return new_queue_found, batch_exit
459
460 def _process_queue_tasks(
461 self,
462 queue: str,
463 queue_lock: Optional[Semaphore],
464 task_ids: Set[str],
465 now: float,
466 log: BoundLogger,
467 ) -> int:
468 """Process tasks in queue."""
469
470 processed_count = 0
471
472 # Get all tasks
473 serialized_tasks = self.connection.mget(
474 [self._key("task", task_id) for task_id in task_ids]
475 )
476
477 # Parse tasks
478 tasks = []
479 for task_id, serialized_task in zip(task_ids, serialized_tasks):
480 if serialized_task:
481 task_data = json.loads(serialized_task)
482 else:
483 # In the rare case where we don't find the task which is
484 # queued (see ReliabilityTestCase.test_task_disappears),
485 # we log an error and remove the task below. We need to
486 # at least initialize the Task object with an ID so we can
487 # remove it.
488 task_data = {"id": task_id}
489
490 task = Task(
491 self.tiger,
492 queue=queue,
493 _data=task_data,
494 _state=ACTIVE,
495 _ts=now,
496 )
497
498 if not serialized_task:
499 # Remove task as per comment above
500 log.error("not found", task_id=task_id)
501 task._move()
502 elif task.id != task_id:
503 log.error("task ID mismatch", task_id=task_id)
504 # Remove task
505 task._move()
506 else:
507 tasks.append(task)
508
509 # Group by task func
510 tasks_by_func: Dict[str, List[Task]] = OrderedDict()
511 for task in tasks:
512 func = task.serialized_func
513 if func in tasks_by_func:
514 tasks_by_func[func].append(task)
515 else:
516 tasks_by_func[func] = [task]
517

Callers 1

_process_from_queueMethod · 0.95

Calls 5

_moveMethod · 0.95
_execute_task_groupMethod · 0.95
TaskClass · 0.85
_keyMethod · 0.80

Tested by

no test coverage detected