Skip to content

Commit

Permalink
avniproject#762 | Metabase package created , API to get status of DB …
Browse files Browse the repository at this point in the history
…sync created and waitforsync eliminated
  • Loading branch information
ombhardwajj committed Jul 27, 2024
1 parent 25dbade commit 55393b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.avni.server.service;
package org.avni.server.service.metabase;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -56,21 +56,6 @@ public int getFieldIdByTableNameAndFieldName(int databaseId, String tableName, S
return -1;
}

public void waitForSyncCompletion(int databaseId) {
while (true) {
String syncStatus = getInitialSyncStatus(databaseId);
if ("complete".equals(syncStatus)) {
return;
}
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException("Thread was interrupted while waiting for sync completion", e);
}
}
}

public String getInitialSyncStatus(int databaseId) {
JsonNode responseBody = databaseRepository.getInitialSyncStatus(databaseId);
return responseBody.path("initial_sync_status").asText();
Expand Down Expand Up @@ -100,7 +85,10 @@ public void createQuestionsForSubjectTypes() {
int databaseId = metabaseService.getGlobalDatabaseId();
int collectionId = metabaseService.getGlobalCollectionId();

waitForSyncCompletion(databaseId);
String syncStatus = getInitialSyncStatus(databaseId);
if (!"complete".equals(syncStatus)) {
throw new RuntimeException("Database initial sync is not complete.");
}

List<String> subjectTypeNames = getSubjectTypeNames(databaseId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.avni.server.service;
package org.avni.server.service.metabase;

import org.avni.server.dao.metabase.CollectionPermissionsRepository;
import org.avni.server.dao.metabase.CollectionRepository;
import org.avni.server.dao.metabase.DatabaseRepository;
import org.avni.server.dao.metabase.GroupPermissionsRepository;
import org.avni.server.domain.Organisation;
import org.avni.server.domain.metabase.*;
import org.avni.server.service.OrganisationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.avni.server.web;
import org.avni.server.service.DatabaseService;
import org.avni.server.service.metabase.DatabaseService;
import org.avni.server.domain.accessControl.PrivilegeType;
import org.avni.server.dao.metabase.MetabaseConnector;
import org.avni.server.dao.metabase.DatabaseRepository;
import org.avni.server.service.MetabaseService;
import org.avni.server.service.metabase.MetabaseService;
import org.avni.server.service.UserService;
import org.avni.server.service.accessControl.AccessControlService;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -31,4 +31,9 @@ public void setupMetabase() {
public void createQuestions() {
databaseService.createQuestionsForSubjectTypes();
}

@GetMapping("/sync-status")
public String getSyncStatus() {
return databaseService.getInitialSyncStatus(metabaseService.getGlobalDatabaseId());
}
}

0 comments on commit 55393b5

Please sign in to comment.