Skip to content

Commit 897d9b9

Browse files
committed
OPHYK-318 Periodically export data required by the datantuonti process
1 parent e7a698a commit 897d9b9

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

organisaatio-service/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,6 @@ organisaatio.tasks.export.lampi-bucket-name=none
8888
organisaatio.tasks.export.lampi-role-arn=none
8989
organisaatio.tasks.export.lampi-external-id=none
9090

91+
organisaatio.tasks.datantuonti.export.enabled=false
92+
9193
varda-rekisterointi.kayttooikeusryhma-id=123

0 commit comments

Comments
 (0)