Pull request #596: RED-6063: Run create tenant async to fix migration timeout

Merge in RED/persistence-service from RED-6063 to master

* commit 'e47269d53cb76028b26d7d6e858c3866799205aa':
  RED-6063: Run create tenant async to fix migration timeout
This commit is contained in:
Dominique Eiflaender 2023-01-24 12:18:57 +01:00 committed by Viktor Seifert
commit a97229c760
2 changed files with 38 additions and 17 deletions

View File

@ -0,0 +1,33 @@
package com.iqser.red.service.peristence.v1.server.migration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.iqser.red.service.peristence.v1.server.service.job.AutomaticAnalysisJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
public class AsyncMigrationStarterService {
private final AutomaticAnalysisJob automaticAnalysisJob;
private final MigrationStarterService migrationStarterService;
@Async
public void runForTenant(String tenantId) {
try {
automaticAnalysisJob.setSchedulingStopped(true);
migrationStarterService.runForTenant(tenantId);
automaticAnalysisJob.setSchedulingStopped(false);
} catch (Exception e) {
automaticAnalysisJob.setSchedulingStopped(false);
throw e;
}
}
}

View File

@ -19,8 +19,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.stereotype.Service;
import com.iqser.red.service.peristence.v1.server.migration.MigrationStarterService;
import com.iqser.red.service.peristence.v1.server.service.job.AutomaticAnalysisJob;
import com.iqser.red.service.peristence.v1.server.migration.AsyncMigrationStarterService;
import com.iqser.red.service.persistence.management.v1.processor.exception.ConflictException;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.multitenancy.entity.TenantEntity;
@ -55,22 +54,19 @@ public class TenantManagementService {
private final LiquibaseProperties liquibaseProperties;
private final ResourceLoader resourceLoader;
private final TenantRepository tenantRepository;
private final AutomaticAnalysisJob automaticAnalysisJob;
private final MigrationStarterService migrationStarterService;
private final AsyncMigrationStarterService asyncMigrationStarterService;
public TenantManagementService(EncryptionDecryptionService encryptionService,
@Qualifier("tenantLiquibaseProperties") LiquibaseProperties liquibaseProperties,
ResourceLoader resourceLoader,
TenantRepository tenantRepository, AutomaticAnalysisJob automaticAnalysisJob, MigrationStarterService migrationStarterService) {
TenantRepository tenantRepository, AsyncMigrationStarterService asyncMigrationStarterService) {
this.encryptionService = encryptionService;
this.liquibaseProperties = liquibaseProperties;
this.resourceLoader = resourceLoader;
this.tenantRepository = tenantRepository;
this.automaticAnalysisJob = automaticAnalysisJob;
this.migrationStarterService = migrationStarterService;
this.asyncMigrationStarterService = asyncMigrationStarterService;
}
@ -101,15 +97,7 @@ public class TenantManagementService {
.build();
tenantRepository.save(tenantEntity);
try{
automaticAnalysisJob.setSchedulingStopped(true);
migrationStarterService.runForTenant(tenantRequest.getTenantId());
automaticAnalysisJob.setSchedulingStopped(false);
} catch (Exception e){
automaticAnalysisJob.setSchedulingStopped(false);
throw e;
}
asyncMigrationStarterService.runForTenant(tenantRequest.getTenantId());
} else {
throw ConflictException.withObjectName("tenant");