def generate_batches(num_records, batch_size):
    """Generate batch size list for splitting a number of tasks into batch jobs.

    Given a number of records to split up, and a batch size, generate a
    stream of batchsize, index pairs"""
    num_batches = num_records // batch_size + 1
    for i in range(0, num_batches):
        if i == num_batches - 1:
            batch_size = num_records - batch_size * i
        if batch_size > 0:
            yield batch_size, i
