def _generate_items_for_subtask(item_querysets, item_fields, total_num_items, items_per_task, total_num_subtasks, course_id):
 num_items_queued = 0
 all_item_fields = list(item_fields)
 all_item_fields.append('pk')
 num_subtasks = 0
 items_for_task = []
 with track_memory_usage('course_email.subtask_generation.memory', course_id):
  for queryset in item_querysets:
   for item in queryset.values(*all_item_fields).iterator():
    if ((len(items_for_task) == items_per_task) and (num_subtasks < (total_num_subtasks - 1))):
     (yield items_for_task)
     num_items_queued += items_per_task
     items_for_task = []
     num_subtasks += 1
    items_for_task.append(item)
  if items_for_task:
   (yield items_for_task)
   num_items_queued += len(items_for_task)
 if (num_items_queued != total_num_items):
  TASK_LOG.info('Number of items generated by chunking %s not equal to original total %s', num_items_queued, total_num_items)

def _generate_items_for_subtask ( item_querysets , item_fields , total_num_items , items_per_task , total_num_subtasks , course_id ) : num_items_queued = 0 all_item_fields = list ( item_fields ) all_item_fields . append ( 'pk' ) num_subtasks = 0 items_for_task = [ ] with track_memory_usage ( 'course_email.subtask_generation.memory' , course_id ) : for queryset in item_querysets : for item in queryset . values ( * all_item_fields ) . iterator ( ) : if ( ( len ( items_for_task ) == items_per_task ) and ( num_subtasks < ( total_num_subtasks - 1 ) ) ) : ( yield items_for_task ) num_items_queued += items_per_task items_for_task = [ ] num_subtasks += 1 items_for_task . append ( item ) if items_for_task : ( yield items_for_task ) num_items_queued += len ( items_for_task ) if ( num_items_queued != total_num_items ) : TASK_LOG . info ( 'Number of items generated by chunking %s not equal to original total %s' , num_items_queued , total_num_items )
generates a chunk of "items" that should be passed into a subtask .