[
https://issues.apache.org/jira/browse/GOBBLIN-2190?focusedWorklogId=955778&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-955778
]
ASF GitHub Bot logged work on GOBBLIN-2190:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 06/Feb/25 07:14
Start Date: 06/Feb/25 07:14
Worklog Time Spent: 10m
Work Description: Copilot commented on code in PR #4093:
URL: https://github.com/apache/gobblin/pull/4093#discussion_r1944213417
##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/ddm/util/TemporalActivityUtils.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.gobblin.temporal.ddm.util;
+
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import io.temporal.activity.ActivityOptions;
+import io.temporal.common.RetryOptions;
+import lombok.experimental.UtilityClass;
+import lombok.extern.slf4j.Slf4j;
+
+import org.apache.gobblin.temporal.ddm.activity.ActivityConfigurationStrategy;
+import org.apache.gobblin.temporal.ddm.activity.ActivityType;
+
+
+/** Utility class for handling Temporal Activity related operations. */
+@UtilityClass
+@Slf4j
+public class TemporalActivityUtils {
+
+ @VisibleForTesting
+ protected static final RetryOptions DEFAULT_RETRY_OPTIONS =
RetryOptions.newBuilder()
+ .setInitialInterval(Duration.ofSeconds(3))
+ .setMaximumInterval(Duration.ofSeconds(100))
+ .setBackoffCoefficient(2)
+ .setMaximumAttempts(4)
+ .build();
+
+ private static final Map<ActivityType, ActivityConfigurationStrategy>
activityConfigurationStrategies = new HashMap<>();
+
+ static {
+ activityConfigurationStrategies.put(ActivityType.GENERATE_WORKUNITS, new
ActivityConfigurationStrategy.GenerateWorkunitsActivityConfigurationStrategy());
+ activityConfigurationStrategies.put(ActivityType.RECOMMEND_SCALING, new
ActivityConfigurationStrategy.RecommendScalingActivityConfigurationStrategy());
+ activityConfigurationStrategies.put(ActivityType.DELETE_WORK_DIRS, new
ActivityConfigurationStrategy.DeleteWorkDirsActivityConfigurationStrategy());
+ activityConfigurationStrategies.put(ActivityType.PROCESS_WORKUNIT, new
ActivityConfigurationStrategy.ProcessWorkunitActivityConfigurationStrategy());
+ activityConfigurationStrategies.put(ActivityType.COMMIT, new
ActivityConfigurationStrategy.CommitActivityConfigurationStrategy());
+ }
+
+ /**
+ * Builds and returns an {@link ActivityOptions} object configured with the
specified {@link ActivityType} and properties.
+ *
+ * @param activityType the type of the activity for which the options are
being built.
+ * @param props the properties to be used for configuring the activity
options.
+ * @return an {@link ActivityOptions} object configured with the specified
activity type and properties.
+ */
+ public static ActivityOptions buildActivityOptions(ActivityType
activityType, Properties props) {
+ return ActivityOptions.newBuilder()
+ .setStartToCloseTimeout(getStartToCloseTimeout(activityType, props))
+ .setRetryOptions(buildRetryOptions(activityType, props))
+ .build();
+ }
+
+ /**
+ * Retrieves the start to close timeout duration for a given {@link
ActivityType} based on the provided properties.
+ *
+ * @param activityType the type of the activity for which the start to close
timeout is being retrieved.
+ * @param props the properties to be used for configuring the timeout.
+ * @return the start to close timeout duration for the specified activity
type.
+ */
+ private static Duration getStartToCloseTimeout(ActivityType activityType,
Properties props) {
+ ActivityConfigurationStrategy activityConfigurationStrategy =
activityConfigurationStrategies.get(activityType);
+ if (activityConfigurationStrategy == null) {
+ log.warn("No configuration strategy found for activity type {}. Using
default start to close timeout.", activityType);
+ return ActivityConfigurationStrategy.defaultStartToCloseTimeout;
+ }
+ return activityConfigurationStrategy.getStartToCloseTimeout(props);
+ }
+
+ /**
+ * Builds and returns an {@link RetryOptions} object configured with the
specified {@link ActivityType} and properties.
+ *
+ * @param activityType the type of the activity for which the options are
being built.
+ * @param props the properties to be used for configuring the activity
options.
+ * @return an {@link RetryOptions} object configured with the specified
activity type and properties.
+ */
+ private static RetryOptions buildRetryOptions(ActivityType activityType,
Properties props) {
+ // Currently returning just the default retry options for each activity
type
+ return DEFAULT_RETRY_OPTIONS;
Review Comment:
The buildRetryOptions method should take into account the activityType and
props to provide more tailored retry options.
```suggestion
ActivityConfigurationStrategy activityConfigurationStrategy =
activityConfigurationStrategies.get(activityType);
if (activityConfigurationStrategy == null) {
log.warn("No configuration strategy found for activity type {}. Using
default retry options.", activityType);
return DEFAULT_RETRY_OPTIONS;
}
return activityConfigurationStrategy.getRetryOptions(props);
```
Issue Time Tracking
-------------------
Worklog Id: (was: 955778)
Time Spent: 1h 50m (was: 1h 40m)
> Implement ActivityTimeoutStrategy for all Temporal Activities
> -------------------------------------------------------------
>
> Key: GOBBLIN-2190
> URL: https://issues.apache.org/jira/browse/GOBBLIN-2190
> Project: Apache Gobblin
> Issue Type: Improvement
> Reporter: Vivek Rai
> Priority: Major
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
> Currently TImeouts of all Temporal Activity are hardcoded and cant change
> during runtime, change those to make them configurable.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)