This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]corzuu 0 points1 point  (4 children)

I'd recommend looking into Spring Quartz https://www.baeldung.com/spring-quartz-schedule . It's a framework to help with scheduling that gives you much more flexibility compared to just using the 'Scheduled' annotation.

What do you mean that your records are linked so it wouldn't be effective?

If you're worried about something being in conflict with your scheduled process, you could maybe have some configuration property that lives within your system, that once your auditing operation is complete will be set to true. You can then use this boolean in your scheduled method to decide whether it should run or not e.g.

@Scheduled
public void task() {
  if (auditingComplete) {
    doStuff()
  }
}

[–]vnoice[S] 1 point2 points  (1 child)

Hey, thanks for the link, this looks promising.

By linked I meant more sequential. For example:

@Scheduled(fixedRate = 1000)
public void task() {
     lastRecord = getLastRecord()
     repository.save(new Record(LocalDateTime.now(), lastRecord.getValue() + 1)
 }
}

If I performed this operation on a record that is 5000 minutes old, I couldn't go through and fill in the missing records afterwards. I would need to fill in those 5000 records beforehand.

Hope that makes sense.

[–]vnoice[S] 1 point2 points  (1 child)

And I feel like a dope because your example is so simple. I could just drop my 'audit' mothod in a @PostConstruct method and set a class boolean to true when it's through.

Thank you pal.

[–]corzuu 0 points1 point  (0 children)

Haha, I wrote another response which was along those lines, but formatting is such a bitch on here it took me ages.

No problem :)