DP-3T / dp3t-sdk-backend

The backend implementation for DP3T
Mozilla Public License 2.0
198 stars 88 forks source link

ScheduledTask with multiple backends running #255

Open iCesofT opened 3 years ago

iCesofT commented 3 years ago

In https://github.com/DP-3T/dp3t-sdk-backend/blob/develop/dpppt-backend-sdk/dpppt-backend-sdk-ws/src/main/java/org/dpppt/backend/sdk/ws/config/WSBaseConfig.java you have a method "configureTasks" that runs periodically to clean the database.

If you have more than one backends running (as expected in an HA environment), you are launching this method for each backend, aren't you?

The optimal solution would be to use Quartz or ShedLock to secure launching the database cleaning.

martinalig commented 3 years ago

Yes this is true. So far we just ignored this because it does not have any sideeffects it multiple services are cleaning the database. Of course, this is not optimal.

Another simple solution would be, to just have an additional profile or application property that enables the master service. But ShedLock looks also quite nice and simple to integrate.

iCesofT commented 3 years ago

I created the PR #262 to solve this issue.

IMHO you should clean the data only once per day so instead of having:

  @Scheduled(fixedRate = 60 * 60 * 1000L, initialDelay = 60 * 1000L)

you could have:

  @Scheduled(cron = "0 0 0 0 * *")
ineiti commented 3 years ago

I created the PR #262 to solve this issue.

IMHO you should clean the data only once per day so instead of having:

  @Scheduled(fixedRate = 60 * 60 * 1000L, initialDelay = 60 * 1000L)

you could have:

  @Scheduled(cron = "0 0 0 0 * *")

I think there is a 0 too much - this would trigger it on every day 0 of the month, i.e., not at all... See https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html#cron--

Also, it's often good practice to chose a 'random' number to avoid different services starting at the same time. So

@Scheduled(cron = "30 42 0 * * *"

Might be better to run it at 12:42:30 am every day.

iCesofT commented 3 years ago

Thanks @ineiti , you're right.