Skip to content

Commit

Permalink
Merge pull request ORCID#6741 from ORCID/SetTimeoutOnLastModifiedandI…
Browse files Browse the repository at this point in the history
…ndexingStatusUpdate

Set timeout on last modifiedand indexing status update
  • Loading branch information
amontenegro authored Mar 7, 2023
2 parents 70964ce + 85289ec commit b3a3481
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.orcid.persistence.dao.ProfileLastModifiedDao;
import org.orcid.persistence.jpa.entities.IndexingStatus;
import org.orcid.persistence.jpa.entities.OrcidAware;
import org.orcid.persistence.jpa.entities.ProfileEntity;
import org.orcid.persistence.util.OrcidStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -118,7 +117,12 @@ public void updateLastModifiedDateAndIndexingStatus(String orcid) {
if (!enabled) {
return;
}
profileLastModifiedDao.updateLastModifiedDateAndIndexingStatus(orcid, IndexingStatus.PENDING);
try {
profileLastModifiedDao.updateLastModifiedDateAndIndexingStatus(orcid, IndexingStatus.PENDING);
} catch(Exception e) {
LOGGER.error("Unable to update last modified and indexing status for " + orcid, e);
}

ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null)
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
Expand All @@ -132,7 +136,12 @@ public void updateLastModifiedDate(String orcid) {
if (!enabled) {
return;
}
profileLastModifiedDao.updateLastModifiedDateWithoutResult(orcid);
try {
profileLastModifiedDao.updateLastModifiedDateWithoutResult(orcid);
} catch(Exception e) {
LOGGER.error("Unable to update last modified for " + orcid, e);
}

ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (sra != null)
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

import org.orcid.persistence.dao.ProfileLastModifiedDao;
import org.orcid.persistence.jpa.entities.IndexingStatus;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;

public class ProfileLastModifiedDaoImpl implements ProfileLastModifiedDao {

@Value("${org.orcid.postgres.query.timeout:30000}")
private Integer queryTimeout;

protected EntityManager entityManager;

/**
Expand All @@ -28,6 +32,8 @@ public void updateLastModifiedDateAndIndexingStatus(String orcid, IndexingStatus
Query updateQuery = entityManager.createQuery("update ProfileEntity set lastModified = now(), indexingStatus = :indexingStatus where orcid = :orcid");
updateQuery.setParameter("orcid", orcid);
updateQuery.setParameter("indexingStatus", indexingStatus);
// Sets a timeout for this query
updateQuery.setHint("javax.persistence.query.timeout", queryTimeout);
updateQuery.executeUpdate();
}

Expand All @@ -36,6 +42,8 @@ public void updateLastModifiedDateAndIndexingStatus(String orcid, IndexingStatus
public void updateLastModifiedDateWithoutResult(String orcid) {
Query query = entityManager.createNativeQuery("update profile set last_modified = now() where orcid = :orcid ");
query.setParameter("orcid", orcid);
// Sets a timeout for this query
query.setHint("javax.persistence.query.timeout", queryTimeout);
query.executeUpdate();
}

Expand Down

0 comments on commit b3a3481

Please sign in to comment.