Skip to content

Commit b3a3481

Browse files
authored
Merge pull request #6741 from ORCID/SetTimeoutOnLastModifiedandIndexingStatusUpdate
Set timeout on last modifiedand indexing status update
2 parents 70964ce + 85289ec commit b3a3481

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

orcid-persistence/src/main/java/org/orcid/persistence/aop/ProfileLastModifiedAspect.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.orcid.persistence.dao.ProfileLastModifiedDao;
1010
import org.orcid.persistence.jpa.entities.IndexingStatus;
1111
import org.orcid.persistence.jpa.entities.OrcidAware;
12-
import org.orcid.persistence.jpa.entities.ProfileEntity;
1312
import org.orcid.persistence.util.OrcidStringUtils;
1413
import org.slf4j.Logger;
1514
import org.slf4j.LoggerFactory;
@@ -118,7 +117,12 @@ public void updateLastModifiedDateAndIndexingStatus(String orcid) {
118117
if (!enabled) {
119118
return;
120119
}
121-
profileLastModifiedDao.updateLastModifiedDateAndIndexingStatus(orcid, IndexingStatus.PENDING);
120+
try {
121+
profileLastModifiedDao.updateLastModifiedDateAndIndexingStatus(orcid, IndexingStatus.PENDING);
122+
} catch(Exception e) {
123+
LOGGER.error("Unable to update last modified and indexing status for " + orcid, e);
124+
}
125+
122126
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
123127
if (sra != null)
124128
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);
@@ -132,7 +136,12 @@ public void updateLastModifiedDate(String orcid) {
132136
if (!enabled) {
133137
return;
134138
}
135-
profileLastModifiedDao.updateLastModifiedDateWithoutResult(orcid);
139+
try {
140+
profileLastModifiedDao.updateLastModifiedDateWithoutResult(orcid);
141+
} catch(Exception e) {
142+
LOGGER.error("Unable to update last modified for " + orcid, e);
143+
}
144+
136145
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
137146
if (sra != null)
138147
sra.setAttribute(sraKey(orcid), null, ServletRequestAttributes.SCOPE_REQUEST);

orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ProfileLastModifiedDaoImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
import org.orcid.persistence.dao.ProfileLastModifiedDao;
1111
import org.orcid.persistence.jpa.entities.IndexingStatus;
12+
import org.springframework.beans.factory.annotation.Value;
1213
import org.springframework.transaction.annotation.Transactional;
1314

1415
public class ProfileLastModifiedDaoImpl implements ProfileLastModifiedDao {
1516

17+
@Value("${org.orcid.postgres.query.timeout:30000}")
18+
private Integer queryTimeout;
19+
1620
protected EntityManager entityManager;
1721

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

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

0 commit comments

Comments
 (0)