def test_ordered_random_task_ids(self): """ Make sure an ordered set list of random strings are returned where the length is number_of_ids """ from furious.marker_tree.identity_utils import ordered_random_ids ids = ordered_random_ids(10) self.assertEqual(len(ids), 10) for index, item in enumerate(ids): self.assertIsNotNone(item) self.assertIsInstance(item, basestring) self.assertEqual(len(item), 3) self.assertEqual(str(index), item[-1]) sorted_ids = sorted(ids) self.assertListEqual(ids, sorted_ids)
def make_markers_for_tasks(cls, tasks, group_id=None, context_callbacks=None): """Builds a marker tree below a parent marker. Assigns ids to Asyncs(tasks) to assign them to leaf nodes. Args: tasks: List of Asyncs. group_id: Id of the parent marker node. context_callbacks: callbacks to be called when a group of tasks are complete. Returns: List of markers. """ markers = [] if len(tasks) > BATCH_SIZE: return cls.split_into_groups( tasks, markers=markers, group_id=group_id, context_callbacks=context_callbacks) else: # Make leaf markers for the tasks. try: markers = [] ids = ordered_random_ids(len(tasks)) for index, task in enumerate(tasks): idx = leaf_persistence_id_from_group_id(group_id, ids[index]) # Assign this leaf marker id to the Async # so when the task is processed, it # can write this marker task.id = idx markers.append(Marker.from_async(task)) except TypeError: raise return markers