snazy commented on code in PR #2180: URL: https://github.com/apache/polaris/pull/2180#discussion_r2637167070
########## tasks/spi/src/main/java/org/apache/polaris/tasks/spi/TaskBehavior.java: ########## @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.polaris.tasks.spi; + +import jakarta.enterprise.context.ApplicationScoped; +import java.time.Instant; +import java.util.Optional; +import org.apache.polaris.tasks.api.TaskBehaviorId; +import org.apache.polaris.tasks.api.TaskId; +import org.apache.polaris.tasks.api.TaskParameter; +import org.apache.polaris.tasks.api.TaskResult; +import org.apache.polaris.tasks.api.Tasks; + +/** + * Task behaviors provide/define how tasks behave and how tasks are handled. + * + * <p>Implementations are provided as {@link ApplicationScoped @ApplicationScoped} beans. + * + * <p>Each behavior must define its {@linkplain TaskParameter input parameter} and {@linkplain + * TaskResult result} types. + */ +public interface TaskBehavior<PARAM extends TaskParameter, RESULT extends TaskResult> { + /** Human-readable name. */ + String name(); + + /** Globally unique ID of the task behavior. */ + TaskBehaviorId id(); + + Class<PARAM> paramType(); + + Class<RESULT> resultType(); + + /** + * Provide a task-runnable that can perform the task behavior's operation. + * + * <p>No guarantees are made about whether CDI is available and which scope is active. + * + * <p>Implementations must <em>never</em> assume that any values or context information from a + * "scheduling" context (think: CDI request context, even propagated) is available. This is + * neither supported by the CDI specification nor practically doable, especially considering that + * task functions are executed "far" in the future and/or on a different node. + */ + TaskFunction<PARAM, RESULT> function(); + + /** + * Generate a task ID. + * + * <p>Task behavior implementations produce either new, globally unique task IDs per submission or + * deterministic task IDs based on the task parameters. + * + * <p>Implementations must include the given {@code realmId} when generating or calculating a task + * ID. Review Comment: "Must" is actually correct here (it must not be null). Implementations defer to any of the 'TaskIdGenerator` functions. `generateNonDeterministicUniqueId` delegates ID generation to the persistence being used. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
