Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScheduledTask with multiple backends running #255

Open
iCesofT opened this issue Oct 2, 2020 · 4 comments
Open

ScheduledTask with multiple backends running #255

iCesofT opened this issue Oct 2, 2020 · 4 comments

Comments

@iCesofT
Copy link
Contributor

iCesofT commented Oct 2, 2020

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
Copy link
Contributor

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
Copy link
Contributor Author

iCesofT commented Oct 10, 2020

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
Copy link
Collaborator

ineiti commented Oct 13, 2020

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
Copy link
Contributor Author

iCesofT commented Oct 13, 2020

Thanks @ineiti , you're right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants