Laucer
Laucer

Reputation: 31

Call Scheduler after method

I have an app, which connects to an API every day and fetches a data (schedulers run every 24h). I would like to add such a functionality: after user registration call schedulers and force fetching data right now. Could you recommend the best approach in Spring?

@Component
public class GetMyFeeEstimateScheduler extends Scheduler {

@Scheduled(fixedDelay = DELAY)
@Transactional
public void fetchGetMyFeeEstimate() throws Exception {
    fetchData();
}

 @PostMapping("/signup")
public void signUp(@RequestBody SignUpRequest signUpRequest) {
  // ...
  // CALL_SCHEDULERS
}

Upvotes: 0

Views: 265

Answers (1)

Ezequiel
Ezequiel

Reputation: 136

I would prefer to expose the fetchData() as a public method in a service class and then call from the controller and from scheduler.

Another option is to call fetchGetMyFeeEstimate directly from the controller.

Upvotes: 1

Related Questions