mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-16 09:55:09 +00:00
Properly purge subscriptions
This commit is contained in:
parent
fe24841350
commit
5b7abf15dc
@ -10,7 +10,7 @@ package ca.uhn.fhir.jpa.dao;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -66,7 +66,7 @@ import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
|
||||
public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subscription>implements IFhirResourceDaoSubscription<Subscription> {
|
||||
public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subscription> implements IFhirResourceDaoSubscription<Subscription> {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoSubscriptionDstu2.class);
|
||||
|
||||
@ -98,7 +98,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
}
|
||||
return table.getId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized List<IBaseResource> getUndeliveredResourcesAndPurge(Long theSubscriptionPid) {
|
||||
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
@ -125,11 +125,16 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
|
||||
// SubscriptionCandidateResource
|
||||
|
||||
Collection<Long> subscriptions = mySubscriptionTableDao.findSubscriptionsWhichNeedToBeChecked(SubscriptionStatusEnum.ACTIVE.getCode(), new Date());
|
||||
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
|
||||
Collection<Long> subscriptions = txTemplate.execute(new TransactionCallback<Collection<Long>>() {
|
||||
@Override
|
||||
public Collection<Long> doInTransaction(TransactionStatus theStatus) {
|
||||
return mySubscriptionTableDao.findSubscriptionsWhichNeedToBeChecked(SubscriptionStatusEnum.ACTIVE.getCode(), new Date());
|
||||
}
|
||||
});
|
||||
|
||||
int retVal = 0;
|
||||
for (final Long nextSubscriptionTablePid : subscriptions) {
|
||||
retVal += txTemplate.execute(new TransactionCallback<Integer>() {
|
||||
@ -140,7 +145,7 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@ -189,9 +194,9 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
|
||||
SubscriptionFlaggedResource nextFlag = new SubscriptionFlaggedResource();
|
||||
Long pid = IDao.RESOURCE_PID.get((IResource) next);
|
||||
|
||||
|
||||
ourLog.info("New resource for subscription: {}", pid);
|
||||
|
||||
|
||||
nextFlag.setResource(myEntityManager.find(ResourceTable.class, pid));
|
||||
nextFlag.setSubscription(theSubscriptionTable);
|
||||
nextFlag.setVersion(next.getIdElement().getVersionIdPartAsLong());
|
||||
@ -201,10 +206,10 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
mySubscriptionFlaggedResourceDataDao.save(flags);
|
||||
|
||||
ourLog.debug("Updating most recent match for subcription {} to {}", subscription.getId().getIdPart(), new InstantDt(mostRecentMatch));
|
||||
|
||||
|
||||
theSubscriptionTable.setMostRecentMatch(mostRecentMatch);
|
||||
mySubscriptionTableDao.save(theSubscriptionTable);
|
||||
|
||||
|
||||
return results.size();
|
||||
}
|
||||
|
||||
@ -238,15 +243,24 @@ public class FhirResourceDaoSubscriptionDstu2 extends FhirResourceDaoDstu2<Subsc
|
||||
return;
|
||||
}
|
||||
|
||||
Date cutoff = new Date(System.currentTimeMillis() - purgeInactiveAfterMillis);
|
||||
Collection<SubscriptionTable> toPurge = mySubscriptionTableDao.findInactiveBeforeCutoff(cutoff);
|
||||
final Date cutoff = new Date(System.currentTimeMillis() - purgeInactiveAfterMillis);
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
Collection<SubscriptionTable> toPurge = txTemplate.execute(new TransactionCallback<Collection<SubscriptionTable>>() {
|
||||
@Override
|
||||
public Collection<SubscriptionTable> doInTransaction(TransactionStatus theStatus) {
|
||||
Collection<SubscriptionTable> toPurge = mySubscriptionTableDao.findInactiveBeforeCutoff(cutoff);
|
||||
toPurge.size();
|
||||
return toPurge;
|
||||
}
|
||||
});
|
||||
|
||||
for (SubscriptionTable subscriptionTable : toPurge) {
|
||||
|
||||
final IdDt subscriptionId = subscriptionTable.getSubscriptionResource().getIdDt();
|
||||
ourLog.info("Deleting inactive subscription {} - Created {}, last client poll {}",
|
||||
new Object[] { subscriptionId.toUnqualified(), subscriptionTable.getCreated(), subscriptionTable.getLastClientPoll() });
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
txTemplate.execute(new TransactionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInTransaction(TransactionStatus theStatus) {
|
||||
|
@ -130,11 +130,16 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subsc
|
||||
|
||||
// SubscriptionCandidateResource
|
||||
|
||||
Collection<Long> subscriptions = mySubscriptionTableDao.findSubscriptionsWhichNeedToBeChecked(SubscriptionStatusEnum.ACTIVE.getCode(), new Date());
|
||||
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
|
||||
Collection<Long> subscriptions = txTemplate.execute(new TransactionCallback<Collection<Long>>() {
|
||||
@Override
|
||||
public Collection<Long> doInTransaction(TransactionStatus theStatus) {
|
||||
return mySubscriptionTableDao.findSubscriptionsWhichNeedToBeChecked(SubscriptionStatusEnum.ACTIVE.getCode(), new Date());
|
||||
}
|
||||
});
|
||||
|
||||
int retVal = 0;
|
||||
for (final Long nextSubscriptionTablePid : subscriptions) {
|
||||
retVal += txTemplate.execute(new TransactionCallback<Integer>() {
|
||||
@ -244,15 +249,24 @@ public class FhirResourceDaoSubscriptionDstu3 extends FhirResourceDaoDstu3<Subsc
|
||||
return;
|
||||
}
|
||||
|
||||
Date cutoff = new Date(System.currentTimeMillis() - purgeInactiveAfterMillis);
|
||||
Collection<SubscriptionTable> toPurge = mySubscriptionTableDao.findInactiveBeforeCutoff(cutoff);
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
final Date cutoff = new Date(System.currentTimeMillis() - purgeInactiveAfterMillis);
|
||||
|
||||
Collection<SubscriptionTable> toPurge = txTemplate.execute(new TransactionCallback<Collection<SubscriptionTable>>() {
|
||||
@Override
|
||||
public Collection<SubscriptionTable> doInTransaction(TransactionStatus theStatus) {
|
||||
Collection<SubscriptionTable> toPurge = mySubscriptionTableDao.findInactiveBeforeCutoff(cutoff);
|
||||
toPurge.size();
|
||||
return toPurge;
|
||||
}
|
||||
});
|
||||
|
||||
for (SubscriptionTable subscriptionTable : toPurge) {
|
||||
|
||||
final IdDt subscriptionId = subscriptionTable.getSubscriptionResource().getIdDt();
|
||||
ourLog.info("Deleting inactive subscription {} - Created {}, last client poll {}",
|
||||
new Object[] { subscriptionId.toUnqualified(), subscriptionTable.getCreated(), subscriptionTable.getLastClientPoll() });
|
||||
TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
txTemplate.execute(new TransactionCallback<Void>() {
|
||||
@Override
|
||||
public Void doInTransaction(TransactionStatus theStatus) {
|
||||
|
@ -131,6 +131,21 @@
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.websocket</groupId>
|
||||
<artifactId>websocket-server</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
|
@ -11,11 +11,13 @@ import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu2;
|
||||
import ca.uhn.fhir.jpa.config.WebsocketDstu2Config;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu2;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
@ -24,6 +26,7 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement()
|
||||
//@Import(WebsocketDstu2Config.class)
|
||||
public class FhirServerConfig extends BaseJavaConfigDstu2 {
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,6 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.hibernate.dialect.DerbyTenSevenDialect;
|
||||
import org.hibernate.dialect.PostgreSQL94Dialect;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
|
@ -175,6 +175,10 @@
|
||||
CLI example uploader couldn't find STU3 examples after CI server
|
||||
was moved to build.fhir.org
|
||||
</action>
|
||||
<action type="fix">
|
||||
Fix issue in JPA subscription module that prevented purging stale
|
||||
subscriptions when many were present on Postgres
|
||||
</action>
|
||||
</release>
|
||||
<release version="2.1" date="2016-11-11">
|
||||
<action type="add">
|
||||
|
Loading…
x
Reference in New Issue
Block a user