mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
CE-938 - Add existingLock to UnableToObtainProcessLockException
This commit is contained in:
@ -103,12 +103,13 @@ public class ProcessLockUtils
|
|||||||
// if inserting failed... see if we can get existing lock //
|
// if inserting failed... see if we can get existing lock //
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
StringBuilder existingLockDetails = new StringBuilder();
|
StringBuilder existingLockDetails = new StringBuilder();
|
||||||
|
ProcessLock existingLock = null;
|
||||||
if(CollectionUtils.nullSafeHasContents(insertOutputRecord.getErrors()))
|
if(CollectionUtils.nullSafeHasContents(insertOutputRecord.getErrors()))
|
||||||
{
|
{
|
||||||
QRecord existingLockRecord = new GetAction().executeForRecord(new GetInput(ProcessLock.TABLE_NAME).withUniqueKey(Map.of("key", key, "processLockTypeId", lockType.getId())));
|
QRecord existingLockRecord = new GetAction().executeForRecord(new GetInput(ProcessLock.TABLE_NAME).withUniqueKey(Map.of("key", key, "processLockTypeId", lockType.getId())));
|
||||||
if(existingLockRecord != null)
|
if(existingLockRecord != null)
|
||||||
{
|
{
|
||||||
ProcessLock existingLock = new ProcessLock(existingLockRecord);
|
existingLock = new ProcessLock(existingLockRecord);
|
||||||
if(StringUtils.hasContent(existingLock.getUserId()))
|
if(StringUtils.hasContent(existingLock.getUserId()))
|
||||||
{
|
{
|
||||||
existingLockDetails.append("Held by: ").append(existingLock.getUserId());
|
existingLockDetails.append("Held by: ").append(existingLock.getUserId());
|
||||||
@ -153,7 +154,8 @@ public class ProcessLockUtils
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
LOG.info("Errors in process lock record after attempted insert", logPair("errors", insertOutputRecord.getErrors()),
|
LOG.info("Errors in process lock record after attempted insert", logPair("errors", insertOutputRecord.getErrors()),
|
||||||
logPair("key", key), logPair("type", typeName), logPair("details", details));
|
logPair("key", key), logPair("type", typeName), logPair("details", details));
|
||||||
throw (new UnableToObtainProcessLockException("A Process Lock already exists for key [" + key + "] of type [" + typeName + "], " + existingLockDetails));
|
throw (new UnableToObtainProcessLockException("A Process Lock already exists for key [" + key + "] of type [" + typeName + "], " + existingLockDetails)
|
||||||
|
.withExistingLock(existingLock));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Created process lock", logPair("id", processLock.getId()),
|
LOG.info("Created process lock", logPair("id", processLock.getId()),
|
||||||
@ -202,12 +204,16 @@ public class ProcessLockUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// var can never be null with current code-path, but prefer defensiveness regardless. //
|
// this variable can never be null with current code-path, but prefer to be defensive regardless //
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@SuppressWarnings("ConstantValue")
|
@SuppressWarnings("ConstantValue")
|
||||||
String suffix = lastCaughtUnableToObtainProcessLockException == null ? "" : ": " + lastCaughtUnableToObtainProcessLockException.getMessage();
|
String suffix = lastCaughtUnableToObtainProcessLockException == null ? "" : ": " + lastCaughtUnableToObtainProcessLockException.getMessage();
|
||||||
throw (new UnableToObtainProcessLockException("Unable to obtain process lock for key [" + key + "] in type [" + type + "] after [" + maxWait + "]" + suffix));
|
|
||||||
|
//noinspection ConstantValue
|
||||||
|
throw (new UnableToObtainProcessLockException("Unable to obtain process lock for key [" + key + "] in type [" + type + "] after [" + maxWait + "]" + suffix)
|
||||||
|
.withExistingLock(lastCaughtUnableToObtainProcessLockException == null ? null : lastCaughtUnableToObtainProcessLockException.getExistingLock())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public class UnableToObtainProcessLockException extends QUserFacingException
|
public class UnableToObtainProcessLockException extends QUserFacingException
|
||||||
{
|
{
|
||||||
|
private ProcessLock existingLock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
@ -49,4 +52,35 @@ public class UnableToObtainProcessLockException extends QUserFacingException
|
|||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Getter for existingLock
|
||||||
|
*******************************************************************************/
|
||||||
|
public ProcessLock getExistingLock()
|
||||||
|
{
|
||||||
|
return (this.existingLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Setter for existingLock
|
||||||
|
*******************************************************************************/
|
||||||
|
public void setExistingLock(ProcessLock existingLock)
|
||||||
|
{
|
||||||
|
this.existingLock = existingLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Fluent setter for existingLock
|
||||||
|
*******************************************************************************/
|
||||||
|
public UnableToObtainProcessLockException withExistingLock(ProcessLock existingLock)
|
||||||
|
{
|
||||||
|
this.existingLock = existingLock;
|
||||||
|
return (this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,8 @@ class ProcessLockUtilsTest extends BaseTest
|
|||||||
.isInstanceOf(UnableToObtainProcessLockException.class)
|
.isInstanceOf(UnableToObtainProcessLockException.class)
|
||||||
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
|
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
|
||||||
.hasMessageContaining("with details: me")
|
.hasMessageContaining("with details: me")
|
||||||
.hasMessageNotContaining("expiring at: 20");
|
.hasMessageNotContaining("expiring at: 20")
|
||||||
|
.matches(e -> ((UnableToObtainProcessLockException) e).getExistingLock() != null);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
// make sure we can create another for a different key //
|
// make sure we can create another for a different key //
|
||||||
@ -179,7 +180,8 @@ class ProcessLockUtilsTest extends BaseTest
|
|||||||
.isInstanceOf(UnableToObtainProcessLockException.class)
|
.isInstanceOf(UnableToObtainProcessLockException.class)
|
||||||
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
|
.hasMessageContaining("Held by: " + QContext.getQSession().getUser().getIdReference())
|
||||||
.hasMessageContaining("with details: me")
|
.hasMessageContaining("with details: me")
|
||||||
.hasMessageContaining("expiring at: 20");
|
.hasMessageContaining("expiring at: 20")
|
||||||
|
.matches(e -> ((UnableToObtainProcessLockException) e).getExistingLock() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user