diff --git a/java/google/registry/batch/MapreduceEntityCleanupAction.java b/java/google/registry/batch/MapreduceEntityCleanupAction.java index df71c7ad4..7cbbc258d 100644 --- a/java/google/registry/batch/MapreduceEntityCleanupAction.java +++ b/java/google/registry/batch/MapreduceEntityCleanupAction.java @@ -172,9 +172,12 @@ public class MapreduceEntityCleanupAction implements Runnable { DateTime cutoffDate = clock.nowUtc().minusDays(defaultedDaysOld); Optional cursor = Optional.absent(); do { + Optional numJobsToRequest = + Optional.fromNullable( + numJobsToDelete.isPresent() ? numJobsToDelete.get() - numJobsProcessed : null); EligibleJobResults batch = mapreduceEntityCleanupUtil.findEligibleJobsByJobName( - jobName.orNull(), cutoffDate, numJobsToDelete, force.or(false), cursor); + jobName.orNull(), cutoffDate, numJobsToRequest, force.or(false), cursor); cursor = batch.cursor(); // Individual batches can come back empty if none of the returned jobs meet the requirements // or if all jobs have been exhausted.