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 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() {
|
public Long getBuildStartTimestamp() {
|
||||||
return this.buildStartTimestamp;
|
return this.buildStartTimestamp;
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,10 @@ public class ArbitraryDataBuildManager extends Thread {
|
|||||||
// Build queue
|
// Build queue
|
||||||
|
|
||||||
public boolean addToBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
public boolean addToBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||||
String resourceId = queueItem.getResourceId();
|
String key = queueItem.getUniqueKey();
|
||||||
if (resourceId == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resourceId = resourceId.toLowerCase();
|
|
||||||
|
|
||||||
if (this.arbitraryDataBuildQueue == null) {
|
if (this.arbitraryDataBuildQueue == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -97,20 +96,20 @@ public class ArbitraryDataBuildManager extends Thread {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.arbitraryDataBuildQueue.put(resourceId, queueItem) != null) {
|
if (this.arbitraryDataBuildQueue.put(key, queueItem) != null) {
|
||||||
// Already in queue
|
// Already in queue
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Added {} to build queue", resourceId);
|
LOGGER.info("Added {} to build queue", queueItem);
|
||||||
|
|
||||||
// Added to queue
|
// Added to queue
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
public boolean isInBuildQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||||
String resourceId = queueItem.getResourceId();
|
String key = queueItem.getUniqueKey();
|
||||||
if (resourceId == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +117,7 @@ public class ArbitraryDataBuildManager extends Thread {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.arbitraryDataBuildQueue.containsKey(resourceId)) {
|
if (this.arbitraryDataBuildQueue.containsKey(key)) {
|
||||||
// Already in queue
|
// Already in queue
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -131,8 +130,8 @@ public class ArbitraryDataBuildManager extends Thread {
|
|||||||
// Failed builds
|
// Failed builds
|
||||||
|
|
||||||
public boolean addToFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
public boolean addToFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
||||||
String resourceId = queueItem.getResourceId();
|
String key = queueItem.getUniqueKey();
|
||||||
if (resourceId == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,29 +144,28 @@ public class ArbitraryDataBuildManager extends Thread {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.arbitraryDataFailedBuilds.put(resourceId, queueItem) != null) {
|
if (this.arbitraryDataFailedBuilds.put(key, queueItem) != null) {
|
||||||
// Already in list
|
// Already in list
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Added {} to failed builds list", resourceId);
|
LOGGER.info("Added {} to failed builds list", queueItem);
|
||||||
|
|
||||||
// Added to queue
|
// Added to queue
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
public boolean isInFailedBuildsList(ArbitraryDataBuildQueueItem queueItem) {
|
||||||
String resourceId = queueItem.getResourceId();
|
String key = queueItem.getUniqueKey();
|
||||||
if (resourceId == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resourceId = resourceId.toLowerCase();
|
|
||||||
|
|
||||||
if (this.arbitraryDataFailedBuilds == null) {
|
if (this.arbitraryDataFailedBuilds == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.arbitraryDataFailedBuilds.containsKey(resourceId)) {
|
if (this.arbitraryDataFailedBuilds.containsKey(key)) {
|
||||||
// Already in list
|
// Already in list
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,10 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String resourceId = next.getKey();
|
|
||||||
ArbitraryDataBuildQueueItem queueItem = next.getValue();
|
ArbitraryDataBuildQueueItem queueItem = next.getValue();
|
||||||
|
|
||||||
if (queueItem == null) {
|
if (queueItem == null) {
|
||||||
this.removeFromQueue(resourceId);
|
this.removeFromQueue(queueItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore builds that have failed recently
|
// Ignore builds that have failed recently
|
||||||
@ -67,13 +66,13 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
|||||||
// Perform the build
|
// Perform the build
|
||||||
LOGGER.info("Building {}...", queueItem);
|
LOGGER.info("Building {}...", queueItem);
|
||||||
queueItem.build();
|
queueItem.build();
|
||||||
this.removeFromQueue(resourceId);
|
this.removeFromQueue(queueItem);
|
||||||
LOGGER.info("Finished building {}", queueItem);
|
LOGGER.info("Finished building {}", queueItem);
|
||||||
|
|
||||||
} catch (MissingDataException e) {
|
} catch (MissingDataException e) {
|
||||||
LOGGER.info("Missing data for {}: {}", queueItem, e.getMessage());
|
LOGGER.info("Missing data for {}: {}", queueItem, e.getMessage());
|
||||||
queueItem.setFailed(true);
|
queueItem.setFailed(true);
|
||||||
this.removeFromQueue(resourceId);
|
this.removeFromQueue(queueItem);
|
||||||
// Don't add to the failed builds list, as we may want to retry sooner
|
// Don't add to the failed builds list, as we may want to retry sooner
|
||||||
|
|
||||||
} catch (IOException | DataException | RuntimeException e) {
|
} 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
|
// Something went wrong - so remove it from the queue, and add to failed builds list
|
||||||
queueItem.setFailed(true);
|
queueItem.setFailed(true);
|
||||||
buildManager.addToFailedBuildsList(queueItem);
|
buildManager.addToFailedBuildsList(queueItem);
|
||||||
this.removeFromQueue(resourceId);
|
this.removeFromQueue(queueItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -90,10 +89,10 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromQueue(String resourceId) {
|
private void removeFromQueue(ArbitraryDataBuildQueueItem queueItem) {
|
||||||
if (resourceId == null) {
|
if (queueItem == null || queueItem.getUniqueKey() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ArbitraryDataBuildManager.getInstance().arbitraryDataBuildQueue.remove(resourceId.toLowerCase());
|
ArbitraryDataBuildManager.getInstance().arbitraryDataBuildQueue.remove(queueItem.getUniqueKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user