change logging output to nil; strange but it seems putting some return value in the loop fixes the hang
don't try to set batch_id if one isn't returned