All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.honhimw.ms.api.Tasks Maven / Gradle / Ivy

There is a newer version: 1.12.0.0
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.github.honhimw.ms.api;

import io.github.honhimw.ms.model.*;
import io.swagger.v3.oas.annotations.Operation;

import java.time.Duration;
import java.util.function.Consumer;

/**
 * The tasks route gives information about the progress of the asynchronous operations.
 *
 * @author hon_him
 * @since 2024-01-02
 */

public interface Tasks {

    /**
     * Get all tasks
     *
     * @param request request
     * @return paginated result
     */
    @Operation(method = "GET", tags = "/tasks")
    Page list(GetTasksRequest request);

    /**
     * Get all tasks
     *
     * @param builder request builder
     * @return paginated result
     */
    @Operation(method = "GET", tags = "/tasks")
    default Page list(Consumer builder) {
        GetTasksRequest.Builder _builder = GetTasksRequest.builder();
        builder.accept(_builder);
        return list(_builder.build());
    }

    /**
     * Delete finished tasks
     *
     * @param request request
     * @return delete task
     */
    @Operation(method = "DELETE", tags = "/tasks")
    TaskInfo delete(GetTasksRequest request);

    /**
     * Delete finished tasks
     *
     * @param builder request builder
     * @return delete task
     */
    @Operation(method = "DELETE", tags = "/tasks")
    default TaskInfo delete(Consumer builder) {
        GetTasksRequest.Builder _builder = GetTasksRequest.builder();
        builder.accept(_builder);
        return delete(_builder.build());
    }

    /**
     * Get a single task.
     *
     * @param uid uid of the requested task
     * @return the requested task
     */
    @Operation(method = "GET", tags = "/tasks/{taskUid}")
    TaskView get(Integer uid);

    /**
     * Cancel any number of enqueued or processing tasks based on their uid, status, type, indexUid,
     * or the date at which they were enqueued, processed, or completed.
     * Task cancelation is an atomic transaction: either all tasks are successfully canceled or none are.
     *
     * @param request A valid uids, statuses, types, indexUids, or date(beforeXAt or afterXAt) parameter is required.
     * @return cancel task
     */
    @Operation(method = "POST", tags = "/tasks/cancel")
    TaskInfo cancel(CancelTasksRequest request);

    /**
     * Cancel any number of enqueued or processing tasks based on their uid, status, type, indexUid,
     * or the date at which they were enqueued, processed, or completed.
     * Task cancelation is an atomic transaction: either all tasks are successfully canceled or none are.
     *
     * @param builder A valid uids, statuses, types, indexUids, or date(beforeXAt or afterXAt) parameter is required.
     * @return cancel task
     */
    @Operation(method = "POST", tags = "/tasks/cancel")
    default TaskInfo cancel(Consumer builder) {
        CancelTasksRequest.Builder _builder = CancelTasksRequest.builder();
        builder.accept(_builder);
        return cancel(_builder.build());
    }

    /**
     * Wait for task finish
     *
     * @param uid task uid
     * @return task info if MSearchConfig#isAwaitExhaustedError() is false
     */
    TaskView await(int uid);

    /**
     * Wait for task finish
     *
     * @param uid         task uid
     * @param maxAttempts max attempts
     * @param fixedDelay  fixed delay
     * @return task info if MSearchConfig#isAwaitExhaustedError() is false
     */
    TaskView await(int uid, int maxAttempts, Duration fixedDelay);

    /**
     * Wait for task finish
     *
     * @param taskInfo task info
     * @return task info if MSearchConfig#isAwaitExhaustedError() is false
     */
    TaskView await(TaskInfo taskInfo);

    /**
     * Wait for task finish
     *
     * @param taskInfo    task info
     * @param maxAttempts max attempts
     * @param fixedDelay  fixed delay
     * @return task info if MSearchConfig#isAwaitExhaustedError() is false
     */
    TaskView await(TaskInfo taskInfo, int maxAttempts, Duration fixedDelay);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy