1
class TaskData {
    int id;
    String status;
}

class TaskDbScheduler() {
     private final SchedulerClient schedulerClient;
    private final OneTimeTask<TaskData> oenTimeTask;
    public TaskInstance<TaskData> schedule(TaskData taskData) {
        Instant nextExecutionTime = taskData.getNextAttempt();
        TaskInstance<TaskData> instance =
                oenTimeTask.instance(taskData.getId()(), taskData);
        boolean scheduled = schedulerClient.scheduleIfNotExists(instance, nextExecutionTime);
        return instance;
    }
}

class TaskHandler{
    TaskDbScheduler scheduler; // causes circular dependency

    void handle(TaskInstance<TaskData> taskInstance, ExecutionContext executionContext) {
        var read = xyzservice.run(taskInstance.getData());

        if(read == fail) {
            // reschedule it after two seconds, with taskdata.toBuilder().status("delayed").build();
        
        }
    }
}

I am using db-scheduler 15.3.0.

I am trying to reschedule a task within the handler on some conditions but it always end up in a circular dependency error. Using SchedulerClient directly in the handler also does not provide the functionality to alter taskdata. Is there a way to reschdule a task this way?

1
  • circular dependency error sounds like something that your IDE would report since, as far as I am aware, it is not a compiler error nor a runtime error. What IDE are you using? Can you edit your question and write which [Java] classes have this circular dependency? In the code in your question, I see that class TaskHandler references class TaskDbScheduler, however I don't see whether class TaskDbScheduler references class TaskHandler. Did I miss something? Commented Apr 14 at 11:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.