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

Give JS example how to use taskId #532

Open
rymsha opened this issue Sep 18, 2024 · 0 comments
Open

Give JS example how to use taskId #532

rymsha opened this issue Sep 18, 2024 · 0 comments

Comments

@rymsha
Copy link
Contributor

rymsha commented Sep 18, 2024

Give example how to prevent multiple tasks to be executed in parallel.
For instance in Java it is:

    public static void checkAlreadySubmitted( final TaskInfo currentTaskInfo, final Collection<TaskInfo> allTasks )
    {
        final TaskId currentTaskId = currentTaskInfo.getId();
        final String currentTaskName = currentTaskInfo.getName();
        final Instant currentTaskStartTime = currentTaskInfo.getStartTime();

        final Optional<TaskInfo> priorTask = allTasks.stream()
            .filter( ti -> !Objects.equals( ti.getId(), currentTaskId ) )
            .filter( ti -> currentTaskName.equals( ti.getName() ) )
            .filter( ti -> !ti.isDone() )
            .filter( ti -> ti.getStartTime().isBefore( currentTaskStartTime ) ||
                ti.getStartTime().equals( currentTaskStartTime ) && ti.getId().toString().compareTo( currentTaskId.toString() ) < 0 )
            .findAny();

        if ( priorTask.isPresent() )
        {
            throw new IllegalStateException( "Task " + currentTaskName + " [" + priorTask.get().getId() + "] is already submitted" );
        }
    }

Maybe it is implemented in js-utils already and we need to give a reference to it?

@ComLock ComLock removed their assignment Dec 18, 2024
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

2 participants