|
3 | 3 | import com.bugsnag.Bugsnag;
|
4 | 4 | import org.apache.log4j.Logger;
|
5 | 5 | import org.avni_integration_service.avni.client.AvniHttpClient;
|
6 |
| -import org.avni_integration_service.integration_data.context.ContextIntegrationSystem; |
7 |
| -import org.avni_integration_service.integration_data.context.IntegrationContext; |
8 |
| -import org.avni_integration_service.integration_data.domain.IntegrationSystem; |
9 |
| -import org.avni_integration_service.integration_data.repository.IntegrationSystemRepository; |
10 | 6 | import org.avni_integration_service.rwb.config.RwbAvniSessionFactory;
|
| 7 | +import org.avni_integration_service.rwb.config.RwbConfig; |
| 8 | +import org.avni_integration_service.rwb.config.RwbContextProvider; |
11 | 9 | import org.avni_integration_service.rwb.worker.RWBUsersNudgeWorker;
|
12 | 10 | import org.avni_integration_service.util.HealthCheckService;
|
13 | 11 | import org.springframework.stereotype.Component;
|
14 | 12 |
|
| 13 | +import static java.lang.String.format; |
| 14 | + |
15 | 15 | @Component
|
16 | 16 | public class AvniRwbMainJob {
|
17 | 17 |
|
| 18 | + private static final String EMPTY_STRING = ""; |
18 | 19 | private static final Logger logger = Logger.getLogger(AvniRwbMainJob.class);
|
19 | 20 |
|
20 |
| - private static final String RWB_HEALTHCHECK_SLUG = "rwb"; |
21 |
| - |
22 | 21 | private final Bugsnag bugsnag;
|
23 |
| - |
24 | 22 | private final HealthCheckService healthCheckService;
|
25 |
| - |
26 | 23 | private final RwbAvniSessionFactory rwbAvniSessionFactory;
|
27 |
| - |
28 | 24 | private final AvniHttpClient avniHttpClient;
|
29 |
| - |
| 25 | + private final RwbContextProvider rwbContextProvider; |
30 | 26 | private final RWBUsersNudgeWorker rwbUsersNudgeWorker;
|
31 |
| - private final IntegrationSystemRepository integrationSystemRepository; |
32 | 27 |
|
33 | 28 | public AvniRwbMainJob(Bugsnag bugsnag, HealthCheckService healthCheckService,
|
34 | 29 | RwbAvniSessionFactory rwbAvniSessionFactory, AvniHttpClient avniHttpClient,
|
35 |
| - RWBUsersNudgeWorker rwbUsersNudgeWorker, IntegrationSystemRepository integrationSystemRepository) { |
| 30 | + RwbContextProvider rwbContextProvider, RWBUsersNudgeWorker rwbUsersNudgeWorker) { |
36 | 31 | this.bugsnag = bugsnag;
|
37 | 32 | this.healthCheckService = healthCheckService;
|
38 | 33 | this.rwbAvniSessionFactory = rwbAvniSessionFactory;
|
39 | 34 | this.avniHttpClient = avniHttpClient;
|
40 | 35 | this.rwbUsersNudgeWorker = rwbUsersNudgeWorker;
|
41 |
| - this.integrationSystemRepository = integrationSystemRepository; |
| 36 | + this.rwbContextProvider = rwbContextProvider; |
42 | 37 | }
|
43 | 38 |
|
44 |
| - public void execute() { |
| 39 | + public void execute(RwbConfig rwbConfig) { |
| 40 | + String rwbIntegrationSystemName = EMPTY_STRING; |
45 | 41 | try {
|
46 |
| - logger.info("Rwb Main Job Started"); |
| 42 | + rwbIntegrationSystemName = rwbConfig.getIntegrationSystem().getName(); |
| 43 | + logger.info(format("Rwb Main Job Started: %s", rwbIntegrationSystemName)); |
| 44 | + rwbContextProvider.set(rwbConfig); |
47 | 45 | avniHttpClient.setAvniSession(rwbAvniSessionFactory.createSession());
|
48 |
| - IntegrationContext.set(new ContextIntegrationSystem(integrationSystemRepository.findBySystemTypeAndName(IntegrationSystem.IntegrationSystemType.rwb, "rwb"))); |
49 | 46 | rwbUsersNudgeWorker.processUsers();
|
50 |
| - healthCheckService.success(RWB_HEALTHCHECK_SLUG); |
51 |
| - logger.info("Rwb Main Job Ended"); |
| 47 | + healthCheckService.success(rwbIntegrationSystemName.toLowerCase()); |
| 48 | + logger.info(format("Rwb Main Job Ended: %s", rwbIntegrationSystemName)); |
52 | 49 | } catch (Exception e) {
|
53 |
| - healthCheckService.failure(RWB_HEALTHCHECK_SLUG); |
54 |
| - logger.error("Failed", e); |
| 50 | + healthCheckService.failure(rwbIntegrationSystemName.toLowerCase()); |
| 51 | + logger.error(format("Rwb Main Job Errored: %s", rwbIntegrationSystemName), e); |
55 | 52 | bugsnag.notify(e);
|
56 | 53 | }
|
57 | 54 | }
|
|
0 commit comments