def when_done(&block)
      call_block = false
      @job_lock.synchronize do
        if completed?
          call_block = true
        else
          @when_done_callbacks << block
        end
      end
      yield if call_block
    end
def when_done(&block)
      call_block = false
      @job_lock.synchronize do
        if completed?
          call_block = true
        else
          @when_done_callbacks << block
        end
      end
      yield if call_block
    end
Execute a given block when the batch has finished processing.  If the batch
 has already finished executing, execute immediately.