I think you need to store some state somewhere that records the last written batch.