forked from Qortal/qortal
Builds are now keyed by service, resourceId and identifier.
This allows for concurrent builds of multiple resources from the same registered name.
This commit is contained in:
parent
f85bbf12ca
commit
67db0f950b
@ -77,6 +77,13 @@ public class ArbitraryDataBuildQueueItem {
|
||||
return this.resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return unique key used to identify this queue item
|
||||
*/
|
||||
public String getUniqueKey() {
|
||||
return String.format("%s-%s-%s", this.service, this.resourceId, this.identifier).toLowerCase();
|
||||
}
|
||||
|
||||
public Long getBuildStartTimestamp() {
|
||||
return this.buildStartTimestamp;
|
||||
}
|
||||
|
@ -77,11 +77,10 @@ public class ArbitraryDataBuildManager extends Thread {
|
||||
// Build queue
|
||||
|
||||
public boolean addToBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||
String resourceId = queueItem.getResourceId();
|
||||
if (resourceId == null) {
|
||||
String key = queueItem.getUniqueKey();
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
resourceId = resourceId.toLowerCase();
|
||||
|
||||
if (this.arbitraryDataBuildQueue == null) {
|
||||
return false;
|
||||
@ -97,20 +96,20 @@ public class ArbitraryDataBuildManager extends Thread {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.arbitraryDataBuildQueue.put(resourceId, queueItem) != null) {
|
||||
if (this.arbitraryDataBuildQueue.put(key, queueItem) != null) {
|
||||
// Already in queue
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGGER.info("Added {} to build queue", resourceId);
|
||||
LOGGER.info("Added {} to build queue", queueItem);
|
||||
|
||||
// Added to queue
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||
String resourceId = queueItem.getResourceId();
|
||||
if (resourceId == null) {
|
||||
String key = queueItem.getUniqueKey();
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -118,7 +117,7 @@ public class ArbitraryDataBuildManager extends Thread {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.arbitraryDataBuildQueue.containsKey(resourceId)) {
|
||||
if (this.arbitraryDataBuildQueue.containsKey(key)) {
|
||||
// Already in queue
|
||||
return true;
|
||||
}
|
||||
@ -131,8 +130,8 @@ public class ArbitraryDataBuildManager extends Thread {
|
||||
// Failed builds
|
||||
|
||||
public boolean addToFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
||||
String resourceId = queueItem.getResourceId();
|
||||
if (resourceId == null) {
|
||||
String key = queueItem.getUniqueKey();
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -145,29 +144,28 @@ public class ArbitraryDataBuildManager extends Thread {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.arbitraryDataFailedBuilds.put(resourceId, queueItem) != null) {
|
||||
if (this.arbitraryDataFailedBuilds.put(key, queueItem) != null) {
|
||||
// Already in list
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGGER.info("Added {} to failed builds list", resourceId);
|
||||
LOGGER.info("Added {} to failed builds list", queueItem);
|
||||
|
||||
// Added to queue
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isInFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
||||
String resourceId = queueItem.getResourceId();
|
||||
if (resourceId == null) {
|
||||
String key = queueItem.getUniqueKey();
|
||||
if (key == null) {
|
||||
return false;
|
||||
}
|
||||
resourceId = resourceId.toLowerCase();
|
||||
|
||||
if (this.arbitraryDataFailedBuilds == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.arbitraryDataFailedBuilds.containsKey(resourceId)) {
|
||||
if (this.arbitraryDataFailedBuilds.containsKey(key)) {
|
||||
// Already in list
|
||||
return true;
|
||||
}
|
||||
|
@ -50,11 +50,10 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
continue;
|
||||
}
|
||||
|
||||
String resourceId = next.getKey();
|
||||
ArbitraryDataBuildQueueItem queueItem = next.getValue();
|
||||
|
||||
if (queueItem == null) {
|
||||
this.removeFromQueue(resourceId);
|
||||
this.removeFromQueue(queueItem);
|
||||
}
|
||||
|
||||
// Ignore builds that have failed recently
|
||||
@ -67,13 +66,13 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
// Perform the build
|
||||
LOGGER.info("Building {}...", queueItem);
|
||||
queueItem.build();
|
||||
this.removeFromQueue(resourceId);
|
||||
this.removeFromQueue(queueItem);
|
||||
LOGGER.info("Finished building {}", queueItem);
|
||||
|
||||
} catch (MissingDataException e) {
|
||||
LOGGER.info("Missing data for {}: {}", queueItem, e.getMessage());
|
||||
queueItem.setFailed(true);
|
||||
this.removeFromQueue(resourceId);
|
||||
this.removeFromQueue(queueItem);
|
||||
// Don't add to the failed builds list, as we may want to retry sooner
|
||||
|
||||
} catch (IOException | DataException | RuntimeException e) {
|
||||
@ -81,7 +80,7 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
// Something went wrong - so remove it from the queue, and add to failed builds list
|
||||
queueItem.setFailed(true);
|
||||
buildManager.addToFailedBuildsList(queueItem);
|
||||
this.removeFromQueue(resourceId);
|
||||
this.removeFromQueue(queueItem);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
@ -90,10 +89,10 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromQueue(String resourceId) {
|
||||
if (resourceId == null) {
|
||||
private void removeFromQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||
if (queueItem == null || queueItem.getUniqueKey() == null) {
|
||||
return;
|
||||
}
|
||||
ArbitraryDataBuildManager.getInstance().arbitraryDataBuildQueue.remove(resourceId.toLowerCase());
|
||||
ArbitraryDataBuildManager.getInstance().arbitraryDataBuildQueue.remove(queueItem.getUniqueKey());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user