|
| 1 | +package fi.vm.sade.organisaatio.datantuonti; |
| 2 | + |
| 3 | +import com.github.kagkarlsson.scheduler.task.ExecutionContext; |
| 4 | +import com.github.kagkarlsson.scheduler.task.FailureHandler; |
| 5 | +import com.github.kagkarlsson.scheduler.task.TaskInstance; |
| 6 | +import com.github.kagkarlsson.scheduler.task.helper.RecurringTask; |
| 7 | +import com.github.kagkarlsson.scheduler.task.schedule.FixedDelay; |
| 8 | +import fi.vm.sade.organisaatio.service.filters.RequestIdFilter; |
| 9 | +import lombok.extern.slf4j.Slf4j; |
| 10 | +import org.slf4j.MDC; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 13 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 14 | +import org.springframework.stereotype.Component; |
| 15 | + |
| 16 | +import java.time.Duration; |
| 17 | + |
| 18 | +@Component |
| 19 | +@Slf4j |
| 20 | +@ConditionalOnProperty(value = "organisaatio.tasks.datantuonti.export.enabled", havingValue = "true") |
| 21 | +public class ExportTask extends RecurringTask<Void> { |
| 22 | + @Autowired |
| 23 | + @Qualifier(value = "DatantuontiExportService") |
| 24 | + private ExportService exportService; |
| 25 | + |
| 26 | + public ExportTask() { |
| 27 | + super( |
| 28 | + "DatantuontiExportTask", |
| 29 | + FixedDelay.of(Duration.ofHours(1)), |
| 30 | + Void.class, |
| 31 | + new FailureHandler.OnFailureReschedule<>(FixedDelay.of(Duration.ofHours(1))) |
| 32 | + ); |
| 33 | + log.info("Creating export task"); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void executeRecurringly(TaskInstance<Void> taskInstance, ExecutionContext executionContext) { |
| 38 | + try { |
| 39 | + MDC.put("requestId", RequestIdFilter.generateRequestId()); |
| 40 | + log.info("Running organisaatio datantuonti export task"); |
| 41 | + exportService.createSchema(); |
| 42 | + log.info("Organisaatio datantuonti export task completed"); |
| 43 | + } finally { |
| 44 | + MDC.remove("requestId"); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments