From 0cbb5ae79e5588755c071f5ec7512f395047800d Mon Sep 17 00:00:00 2001 From: farneser Date: Thu, 14 Dec 2023 03:44:15 +0300 Subject: [PATCH] feat: timezone and archive column setup by env --- README.md | 10 ++++--- .../scheduler/services/SchedulerService.kt | 26 ++++++++++++------- ...itional-spring-configuration-metadata.json | 10 +++++++ src/main/resources/application-dev.properties | 2 ++ src/main/resources/application.properties | 4 ++- src/test/resources/application.properties | 2 ++ 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 02d48ae..c2af9ab 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,12 @@ Service images are available on [Docker Hub](https://hub.docker.com/r/farneser/t ### Application -| Parameter | Default value | Description | -|----------------|---------------|-------------------------------------------------| -| SCHEDULER_CRON | 0 0 0 * * * | Scheduler cron expression (default at midnight) | -| LOG_LEVEL | INFO | Spring application logging level | +| Parameter | Default value | Description | +|-----------------------------------|-----------------|-------------------------------------------------| +| SCHEDULER_CRON | `0 0 0 * * *` | Scheduler cron expression (default at midnight) | +| SCHEDULER_LOG_LEVEL | `INFO` | Spring application logging level | +| SCHEDULER_TIMEZONE | `Europe/Minsk ` | Scheduler timezone | +| SCHEDULER_ARCHIVED_COLUMN_ENABLED | `false` | Scheduler statistics archived column enabled | ### Postgres diff --git a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt index ef48172..dae0a40 100644 --- a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt +++ b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt @@ -6,6 +6,7 @@ import dev.farneser.tasktracker.scheduler.dto.StatisticDto import dev.farneser.tasktracker.scheduler.services.messages.MessageService import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Value import org.springframework.scheduling.annotation.EnableScheduling import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component @@ -22,7 +23,10 @@ class SchedulerService( val log: Logger = LoggerFactory.getLogger(SchedulerService::class.java) } - @Scheduled(cron = "\${scheduler.cron:0 0 0 * * *}") + @Value("\${scheduler.archivedColumnEnabled:false}") + val archivedColumnEnabled: Boolean = false + + @Scheduled(cron = "\${scheduler.cron:0 0 0 * * *}", zone = "\${scheduler.timezone:Europe/Minsk}") fun scheduledNotifier() { log.info("Scheduled task started at ${System.currentTimeMillis()}") @@ -31,29 +35,33 @@ class SchedulerService( for (user in users) { - log.info("Getting statistic for user: ${user.email} started at ${System.currentTimeMillis()}") + log.info("Getting statistics for user: ${user.email} started at ${System.currentTimeMillis()}") - val statistic = StatisticDto(user.email) + val statistics = StatisticDto(user.email) val columns = columnService.getByUserId(user.id) for (column in columns) { val tasks = taskService.getByColumnId(column.id, user.id) - statistic.columns.add(ColumnDto(column, tasks)) + statistics.columns.add(ColumnDto(column, tasks)) log.debug("Tasks in column ${column.columnName}: $tasks") } - val archivedTasks = taskService.getByColumnId(-1, user.id) + if (archivedColumnEnabled) { + log.debug("Archived column enabled") + + val archivedTasks = taskService.getByColumnId(-1, user.id) - statistic.columns.add(ColumnDto("Archived", -1, archivedTasks)) + statistics.columns.add(ColumnDto("Archived", -1, archivedTasks)) - log.debug("Archived tasks: $archivedTasks") + log.debug("Archived tasks: $archivedTasks") + } - messageService.sendScheduledMessage(Gson().toJson(statistic)) + messageService.sendScheduledMessage(Gson().toJson(statistics)) - log.info("User {} notified successfully with statistic: {}", user.email, statistic) + log.info("User {} notified successfully with statistic: {}", user.email, statistics) } log.info("Scheduled task finished at ${System.currentTimeMillis()} users notified: ${users.size}") 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 08e5123..cb1337e 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -4,6 +4,16 @@ "name": "scheduler.cron", "type": "java.lang.String", "description": "Cron expression for the scheduler. Default in every midnight." + }, + { + "name": "scheduler.archivedColumnEnabled", + "type": "java.lang.String", + "description": "Enable or disable the archived column. Default is false." + }, + { + "name": "scheduler.timezone", + "type": "java.lang.String", + "description": "Timezone for the scheduler. Default is Europe/Minsk." } ] } \ No newline at end of file diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 176f0e0..bb98138 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -15,6 +15,8 @@ spring.rabbitmq.password=rabbitmq # scheduler # every minute scheduler.cron=0 * * * * * +scheduler.timezone=Europe/Minsk +scheduler.archivedColumnEnabled=false # spring logging.level.root=DEBUG diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3bfff42..69181aa 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -15,5 +15,7 @@ spring.rabbitmq.password=${RABBITMQ_PASSWORD:rabbitmq} # scheduler # default at midnight scheduler.cron=${SCHEDULER_CRON:0 0 0 * * *} +scheduler.timezone=${SCHEDULER_TIMEZONE:Europe/Minsk} +scheduler.archivedColumnEnabled=${SCHEDULER_ARCHIVED_COLUMN_ENABLED:false} # spring -logging.level.root=${LOG_LEVEL:INFO} \ No newline at end of file +logging.level.root=${SCHEDULER_LOG_LEVEL:INFO} \ No newline at end of file diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index a7de91b..e5a3633 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -5,5 +5,7 @@ spring.jpa.hibernate.ddl-auto=none # scheduler # every minute scheduler.cron=0 * * * * * +scheduler.timezone=Europe/Minsk +scheduler.archivedColumnEnabled=false # spring spring.profiles.active=test \ No newline at end of file