Skip to content

Commit

Permalink
feat: timezone and archive column setup by env
Browse files Browse the repository at this point in the history
  • Loading branch information
farneser committed Dec 14, 2023
1 parent 83b55d3 commit 0cbb5ae
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()}")
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
}
2 changes: 2 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
logging.level.root=${SCHEDULER_LOG_LEVEL:INFO}
2 changes: 2 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0cbb5ae

Please sign in to comment.