Ahmed Ibrahim
Ahmed Ibrahim

Reputation: 21

Can I set an expired time for record with spring boot and MySQL?

I have a task to develop a simple app that handle requests (user sends requests and other accept or reject) and I need to develop a background task that cancels all pending requests that exceed 2 minutes without receiving user accept or reject.

What is the best technique to develop this ?

I'm using Java spring boot and MySQL for the database

Upvotes: 1

Views: 1250

Answers (2)

Arthur Klezovich
Arthur Klezovich

Reputation: 2819

What you want is the Spring @Scheduled annotation.

@Scheduled(fixedDelay = 1000)
public void scheduleFixedDelayTask() {
    System.out.println(
      "Fixed delay task - " + System.currentTimeMillis() / 1000);
}

Here are the details about how to setup and configure it

Upvotes: 1

Ali Fidanli
Ali Fidanli

Reputation: 1372

I would reccomend mysql scheduled job that works every minute and do some kind of operation like :

update task set status = 'reject' where taskdate < DATE_SUB(NOW(), INTERVAL 2 MINUTE)

you can find detailed description here

Upvotes: 1

Related Questions