Skip to content

Conversation

@zyme
Copy link
Collaborator

@zyme zyme commented Dec 30, 2020

For DDP-5479, Instead of extracting long lists of KitRequests and passing them around--which is contributing to memory pressure--these changes stream things a bit more so that as we work through the result set of pending kits, we update its status from GBF as we go.

While making these changes, I found another latent bug that can result in inconsistent transactions. I fixed this by passing around Connections, which rippled through a number of classes unrelated to the driving changes above.

I also suspect that some of our larger log statements--which pull fairly large objects into a String--may be contributing to our problems, so I removed those.

zyme added 3 commits December 29, 2020 21:34
…hrough them, stream through the data, updating as we go. Along the way, to fix some non-transactional behavior, it was necessary to add `Connection` param to many methods, which rippled into a number of classes as this is a fairly wide refactor in addition to the streaming change.
ArrayList<KitRequest> kitRequests = shipper.getKitRequestsNotDone(kitType.getInstanceId());
shipper.orderStatus(kitRequests);
kitRequests.clear();
shipper.updateOrderStatusForPendingKitRequests(kitType.getInstanceId());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a large object here and passing it around, this changes things to streaming.

else {
logger.error("delivered kitDDPNotification was null for " + kit.getExternalOrderNumber());

if (!isReturn) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much is really changed here--just passing in a Connection and adjusting accordingly.

stmt.setLong(2, externalOrderDate);
stmt.setString(3, dsmKitRequestId);
stmt.setString(4, externalOrderStatus);
public static void updateKitRequest(Connection conn, String externalOrderStatus, long externalOrderDate, String dsmKitRequestId) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another pass-in-the-Connection change is the only thing going on here.


public void orderCancellation(ArrayList<KitRequest> kitRequests) throws Exception;

public ArrayList<KitRequest> getKitRequestsNotDone(int instanceId);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to GBFRequestUtil, rather than the interface, since it's now used only when testing GBFRequestUtil.

for (String dsmKitRequestId : dsmKitRequestIds) {
KitRequestExternal.updateKitRequest(status.getOrderStatus(), System.currentTimeMillis(), dsmKitRequestId);// in order to update time for the next 24 hour check we need this
}
public void orderStatus(Connection conn, KitRequest kit) throws Exception {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than iterating on a list, this now operates on a single kit at a time, using the passed-in Connection.

rs.getLong(DBConstants.EXTERNAL_ORDER_DATE));
numOrdersProcessed.incrementAndGet();
try {
orderStatus(conn, kitRequest);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping this in a try/catch so we can keep going even if we run into a problem for a single kitRequest.

// uploadKit();

ExternalShipper shipper = (ExternalShipper) Class.forName(DSMServer.getClassName("gbf")).newInstance();//GBFRequestUtil
GBFRequestUtil shipper = new GBFRequestUtil();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to instantiate via reflection, since we know exactly the GBFRequestUtil class we're testing here.

String sendRequest = DSMServer.getBaseUrl(getExternalShipperName()) + STATUS_ENDPOINT;
logger.info("payload: " + payload.toString());
Response gbfResponse = executePost(Response.class, sendRequest, payload.toString(), DSMServer.getApiKey(getExternalShipperName()));
logger.info(gbfResponse.getXML());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be blowing things up--big log of a potentially very large string of XML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants