Move pruning to separate method
@@ -248,14 +248,7 @@ public class JobController {
version.get(),
testPackageBytes);
- application.get().deployments().values().stream()
- .map(Deployment::applicationVersion)
- .min(Comparator.comparingLong(applicationVersion -> applicationVersion.buildNumber().getAsLong()))
- .ifPresent(oldestDeployed -> {
- controller.applications().applicationStore().prune(id, oldestDeployed);
- controller.applications().applicationStore().prune(TesterId.of(id), oldestDeployed);
- });
-
+ prunePackages(id);
controller.applications().storeWithUpdatedConfig(application.withBuiltInternally(true), new ApplicationPackage(packageBytes));
notifyOfNewSubmission(id, projectId, revision, run);
@@ -355,6 +348,18 @@ public class JobController {
controller.applications().deploymentTrigger().notifyOfCompletion(report);
}
+ private void prunePackages(ApplicationId id) {
+ controller.applications().lockIfPresent(id, application -> {
+ application.get().deployments().values().stream()
+ .map(Deployment::applicationVersion)
+ .min(Comparator.comparingLong(applicationVersion -> applicationVersion.buildNumber().getAsLong()))
+ .ifPresent(oldestDeployed -> {
+ controller.applications().applicationStore().prune(id, oldestDeployed);
+ controller.applications().applicationStore().prune(TesterId.of(id), oldestDeployed);
+ });
+ });
+ }
+
/** Locks and modifies the list of historic runs for the given application and job type. */
private void locked(ApplicationId id, JobType type, Consumer<SortedMap<RunId, Run>> modifications) {
try (Lock __ = curator.lock(id, type)) {
