Using A Recursive call for Worker Polling

My application has a worker and two activities:

  • The first activity queries an external service to get a status update
  • The second activity sends a message to our front-end

My current implementation is:

public class NotifyWorkerImpl {

public void notify(Input input, String previousStatus) {
        Result status = externalService.getStatus(input.getId);
        
        if (!previousStatus.equals(status)) {
             notificationActivities.sendNotification(status);
        }
        
        Workflow.sleep(Duration.ofSeconds(status.duration));
        notify(input, status);
    }
}

Essentially the first call to notify creates one worker. This worker remains alive and after the sleep, the same method will be called again for retrieving the next state change.
The sleep could be anywhere from 15secs to multiple hours (max would be 24 hours).

I have been following this thread:

And curious if I should go with one of those suggestions(maybe the third one?) instead of using a recursive call. I also don’t want to hit the 50k event history and not sure if this solution would cause that to happen.

I wouldn’t use recursion, but just a normal loop up to a fixed number of iterations, let’s say 100 and then call continue-as-new to reset workflow history which would allow never hitting the history size limit.