From eb362d5fd65e0fdc32472fcac65d0207c768a6c2 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Fri, 24 Nov 2023 08:47:39 +0100 Subject: [PATCH] Feature/define intervals for data import (#105) --- .../workflows/publish-dev-docker-image.yml | 72 +++++++++++++++++++ .../scheduled/DataImportScheduler.java | 2 +- ...itional-spring-configuration-metadata.json | 10 +++ src/main/resources/application.yml | 5 +- src/test/resources/application.yml | 5 +- 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish-dev-docker-image.yml diff --git a/.github/workflows/publish-dev-docker-image.yml b/.github/workflows/publish-dev-docker-image.yml new file mode 100644 index 00000000..4c9862af --- /dev/null +++ b/.github/workflows/publish-dev-docker-image.yml @@ -0,0 +1,72 @@ +name: Publish DEV Docker Image + +on: + push: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + create-docker-image: + name: Create Docker Image + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Java 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: microsoft + + - name: Build with Maven + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FARM21_API_TOKEN: ${{ secrets.FARM21_API_TOKEN }} + SOILSCOUT_USERNAME: ${{ secrets.SOILSCOUT_USERNAME }} + SOILSCOUT_PASSWORD: ${{ secrets.SOILSCOUT_PASSWORD }} + AGRANIMO_USERNAME: ${{ secrets.AGRANIMO_USERNAME }} + AGRANIMO_PASSWORD: ${{ secrets.AGRANIMO_PASSWORD }} + SENTEK_API_TOKEN: ${{ secrets.SENTEK_API_TOKEN }} + AGVOLUTION_USERNAME: ${{ secrets.AGVOLUTION_USERNAME }} + AGVOLUTION_PASSWORD: ${{ secrets.AGVOLUTION_PASSWORD }} + SENSOTERRA_USERNAME: ${{ secrets.SENSOTERRA_USERNAME }} + SENSOTERRA_PASSWORD: ${{ secrets.SENSOTERRA_PASSWORD }} + API_KEY: ${{ secrets.API_KEY }} + WEENAT_USERNAME: ${{ secrets.WEENAT_USERNAME }} + WEENAT_PASSWORD: ${{ secrets.WEENAT_PASSWORD }} + MICROSTREAM_STORAGE_DIRECTORY: ./microstream-integration-test + IMAGE_PATH_BASE_URL: localhost:8080/images + run: mvn -B verify --file pom.xml --settings .github/settings.xml + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: develop, latest + + - name: Build Docker Image + uses: docker/build-push-action@v3 + with: + context: . + push: ${{ github.ref_type == 'tag' }} + file: .github/dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java b/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java index 1b759627..5b53cc2f 100644 --- a/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java +++ b/src/main/java/de/app/fivegla/scheduled/DataImportScheduler.java @@ -29,7 +29,7 @@ public DataImportScheduler(ApplicationEventPublisher applicationEventPublisher, /** * Schedule data import for all manufacturer. */ - @Scheduled(cron = "${app.scheduled.cron}") + @Scheduled(initialDelayString = "${app.scheduled.data-import.initial-delay}", fixedDelayString = "${app.scheduled.data-import.delay}") public void scheduleDataImport() { Arrays.stream(Manufacturer.values()) .forEach(manufacturer -> { diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json index af4ef78f..9617153f 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -309,6 +309,16 @@ "name": "app.fiware.tenant", "type": "java.lang.String", "description": "The FIWARE tenant." + }, + { + "name": "app.scheduled.data-import.initial-delay", + "type": "java.lang.String", + "description": "The initial delay for the scheduled data import." + }, + { + "name": "app.scheduled.data-import.delay", + "type": "java.lang.String", + "description": "The delay for the scheduled data import." } ] } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 20468b30..008e20e7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -65,7 +65,10 @@ app: username: ${WEENAT_USERNAME} password: ${WEENAT_PASSWORD} scheduled: - cron: "0 0 */1 * * *" # every hour + data-import: + # Spring Boot uses ISO-8601 durations, https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence) + initial-delay: PT10S # 10 seconds + delay: PT30M # 30 minutes daysInThePastForInitialImport: 3 fiware: contextBrokerUrl: ${CONTEXT_BROKER_URL} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 96d7a808..85d7be26 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -65,7 +65,10 @@ app: username: ${WEENAT_USERNAME} password: ${WEENAT_PASSWORD} scheduled: - cron: "0 0 */1 * * *" # every hour + data-import: + # Spring Boot uses ISO-8601 durations, https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html#parse(java.lang.CharSequence) + initial-delay: PT10S # 10 seconds + delay: PT30M # 30 minutes daysInThePastForInitialImport: 1 fiware: contextBrokerUrl: https://orion.5gla.de