threejeez
threejeez

Reputation: 2324

Spring @Scheduled After A Server Restart

I'm creating a mechanism in my web server whereby a scheduled task will execute every 15 minutes and notify users if any activity has occurred within that time frame. It would work as follows:

  1. Annotate a with @Scheduled and schedule to run every 15 minutes
  2. When the task runs, scrape the database for any changes within 15 minutes of the current time

A couple problems I can see:

Has anyone dealt with this before? I'm thinking that this should really be a task external to the web servers... that would solve the issue of duplicate emails being sent, but it wouldn't solve the server bounce issue.

Any ideas on how to solve would be greatly appreciated!

Upvotes: 1

Views: 1958

Answers (1)

Liam
Liam

Reputation: 2837

I would have done the following steps to perform the scheduling:

  1. On Application startup query for tasks from database (only those which don't have a dirty flag set to false) and schedule it.
  2. On each run of scheduled task put a dirty flag to suggest the task has run

Because I will be retrieving those tasks only which are marked as dirty, the issue of multiple emails should not occur even on server startup.

Upvotes: 2

Related Questions