Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #380 from OpenSRP/tbreach_issue379
Browse files Browse the repository at this point in the history
TBR: Fix issue of duplicate event server versions
  • Loading branch information
Ephraim (Keyman) Muhia authored Feb 27, 2018
2 parents a6602b8 + dd01789 commit b4c73cd
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,22 @@ public void processEvent() {
}
}

private void addServerVersion() {
private synchronized void addServerVersion() {
try {
List<Client> clients = allClients.findByEmptyServerVersion();
long currentTimeMillis = getCurrentMilliseconds();
while (clients != null && !clients.isEmpty()) {
for (Client client : clients) {
try {
Thread.sleep(1);
client.setServerVersion(getCurrentMilliseconds());
client.setServerVersion(currentTimeMillis);
allClients.update(client);
logger.debug("Add server_version: found new client " + client.getBaseEntityId());
}
catch (InterruptedException e) {
logger.error("", e);
}
currentTimeMillis += 1;
}
clients = allClients.findByEmptyServerVersion();
}
Expand All @@ -141,14 +143,15 @@ private void addServerVersion() {
try {
Thread.sleep(1);
event = eventService.processOutOfArea(event);
event.setServerVersion(getCurrentMilliseconds());
event.setServerVersion(currentTimeMillis);
allEvents.update(event);

logger.debug("Add server_version: found new event " + event.getBaseEntityId());
}
catch (InterruptedException e) {
logger.error("", e);
}
currentTimeMillis += 1;
}

events = allEvents.findByEmptyServerVersion();
Expand Down

0 comments on commit b4c73cd

Please sign in to comment.