snazy commented on code in PR #2180: URL: https://github.com/apache/polaris/pull/2180#discussion_r2637174652
########## tasks/store/src/main/java/org/apache/polaris/tasks/store/TaskState.java: ########## @@ -0,0 +1,146 @@ +/* + * 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.store; + +import static com.google.common.base.Preconditions.checkState; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.time.Instant; +import java.util.Optional; +import org.apache.polaris.immutables.PolarisImmutable; +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.spi.TaskBehavior; +import org.apache.polaris.tasks.spi.TaskExecutionError; +import org.immutables.value.Value; + +/** Represents the state of a particular task execution. */ +@PolarisImmutable +@JsonSerialize(as = ImmutableTaskState.class) +@JsonDeserialize(as = ImmutableTaskState.class) +public interface TaskState { + TaskId taskId(); + + /** + * ID of the {@linkplain TaskBehavior behavior}. + * + * <p>Users of a {@link TaskState} object must be aware that a {@linkplain TaskBehavior behavior} + * may not be available. Unknown behaviors must not be prematurely deleted, because another + * instance might be able to handle those behaviors. Rolling upgrades are legit use cases for the + * case hitting an unknown behavior. + */ + TaskBehaviorId behaviorId(); + + /** The current task status. */ + TaskStatus status(); + + /** Represents an error message, intended for humans, not machines. */ + @JsonInclude(JsonInclude.Include.NON_ABSENT) + Optional<TaskExecutionError> error(); + + /** Represents the earliest timestamp when a task can be run (again). */ + @JsonInclude(JsonInclude.Include.NON_ABSENT) + Optional<Instant> scheduleNotBefore(); + + @JsonInclude(JsonInclude.Include.NON_ABSENT) + Optional<Instant> executedAt(); + + /** + * Represents the earliest timestamp when a task service can assume that a {@link + * TaskStatus#RUNNING RUNNING} task is lost and should be re-started. Only valid for {@link + * TaskStatus#RUNNING RUNNING}. + */ + @JsonInclude(JsonInclude.Include.NON_ABSENT) + Optional<Instant> lostNotBefore(); + + TaskParameter taskParam(); + + @JsonInclude(JsonInclude.Include.NON_ABSENT) + Optional<TaskResult> taskResult(); + + static ImmutableTaskState.Builder builder() { + return ImmutableTaskState.builder(); + } + + @SuppressWarnings("UnnecessaryDefault") + @JsonIgnore + default boolean isScheduled(Instant now) { Review Comment: Technically, this function is used to determine whether a task _can_ be scheduled. Updated this a bit. -- 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]
