Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function Request: putInstance #539

Open
beilCrxmarkets opened this issue Sep 19, 2024 · 0 comments
Open

Function Request: putInstance #539

beilCrxmarkets opened this issue Sep 19, 2024 · 0 comments

Comments

@beilCrxmarkets
Copy link

If SchedulerClient.reschedule() is called with a TaskInstance that does not yet exist, an exception is thrown. You must therefore always check whether there is already a scheduled TaskInstance before you can call reschedule. We would therefore be pleased to have a putInstance method that automatically schedules a TaskInstance if there is none to reschedule. This is particularly convenient for dynamic recurring tasks, as these first have to be initialized.

    void putInstance(TaskInstance<Void> taskInstance, Instant executionTime) {
        var optionalExecutionObject = schedulerClient.getScheduledExecutions()
                .stream()
                .filter(e -> e.getTaskInstance().getId().equals(taskInstance.getId()))
                .findFirst();
        if (optionalExecutionObject.isPresent()) {
            schedulerClient.reschedule(taskInstance, executionTime);
        }
        else {
            schedulerClient.scheduleIfNotExists(taskInstance, executionTime);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant