Skip to content

Commit dfe250a

Browse files
committed
Make static file publish step async
1 parent 4a74cb0 commit dfe250a

File tree

1 file changed

+23
-3
lines changed
  • zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing

1 file changed

+23
-3
lines changed

zebedee-cms/src/main/java/com/github/onsdigital/zebedee/model/publishing/Publisher.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public static boolean executePublish(Collection collection, CollectionReader col
115115
boolean success = false;
116116
final String collectionId = collection.getDescription().getId();
117117

118+
Future<Boolean> staticFilesPublishingFuture = null;
119+
if (CMSFeatureFlags.cmsFeatureFlags().isStaticFilesPublishingEnabled()) {
120+
staticFilesPublishingFuture = performStaticFilesPublish(collection);
121+
}
122+
118123
Future<ImageServicePublishingResult> imageFuture = null;
119124
if (CMSFeatureFlags.cmsFeatureFlags().isImagePublishingEnabled()) {
120125
imageFuture = publishImages(collection);
@@ -139,11 +144,13 @@ public static boolean executePublish(Collection collection, CollectionReader col
139144

140145
if (CMSFeatureFlags.cmsFeatureFlags().isStaticFilesPublishingEnabled()) {
141146
try {
142-
staticFilesServiceSupplier.getService().publishCollection(collection);
143-
success &= true;
147+
if (staticFilesPublishingFuture == null) {
148+
throw new Exception("static files publishing future unexpectedly null on completion of publishing");
149+
}
150+
success &= staticFilesPublishingFuture.get();
144151
} catch (Exception e) {
145152
error().data("collectionId", collectionId).data("publishing", true)
146-
.logException(e, "Exception thrown when performing static file publish()");
153+
.logException(e, "Exception thrown when completing static file publish()");
147154
success = false;
148155
}
149156
}
@@ -788,6 +795,19 @@ private static Future<ImageServicePublishingResult> publishImages(Collection col
788795
});
789796
}
790797

798+
private static Future<Boolean> performStaticFilesPublish(Collection collection) {
799+
return apiPool.submit(() -> {
800+
try {
801+
staticFilesServiceSupplier.getService().publishCollection(collection);
802+
return true;
803+
} catch (Exception e) {
804+
error().data("collectionId", collection.getDescription().getId()).data("publishing", true)
805+
.logException(e, "Exception thrown when performing static file publish()");
806+
return false;
807+
}
808+
});
809+
}
810+
791811
// Valid CMDDataset uris for published CMD versions of a dataset (edition) -
792812
// /dataset/{datatsetId}/editions/{edition}/versions/{version}/metadata
793813
protected static boolean isValidCMDDatasetURI(String uri) {

0 commit comments

Comments
 (0)