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 #381 from OpenSRP/master_issue379
Browse files Browse the repository at this point in the history
Master: Fix issue of duplicate server versions
  • Loading branch information
Ephraim (Keyman) Muhia authored Feb 27, 2018
2 parents 9fca531 + 3c5b124 commit bbc5e13
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@ public void processEvent(MotechEvent motechEvent) {
}
}

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 @@ -143,15 +145,16 @@ private void addServerVersion() {
for (Event event : events) {
try {
Thread.sleep(1);
event=eventService.processOutOfArea(event);
event.setServerVersion(getCurrentMilliseconds());
event = eventService.processOutOfArea(event);
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 bbc5e13

Please sign in to comment.