10
10
import io .airbyte .scheduler .models .JobRunConfig ;
11
11
import io .temporal .activity .Activity ;
12
12
import io .temporal .api .common .v1 .WorkflowExecution ;
13
+ import io .temporal .api .namespace .v1 .NamespaceConfig ;
13
14
import io .temporal .api .namespace .v1 .NamespaceInfo ;
15
+ import io .temporal .api .workflowservice .v1 .DescribeNamespaceRequest ;
14
16
import io .temporal .api .workflowservice .v1 .DescribeNamespaceResponse ;
15
17
import io .temporal .api .workflowservice .v1 .ListNamespacesRequest ;
18
+ import io .temporal .api .workflowservice .v1 .UpdateNamespaceRequest ;
16
19
import io .temporal .client .ActivityCompletionException ;
17
20
import io .temporal .client .WorkflowClient ;
18
21
import io .temporal .client .WorkflowOptions ;
30
33
import java .util .concurrent .Executors ;
31
34
import java .util .concurrent .ScheduledExecutorService ;
32
35
import java .util .concurrent .TimeUnit ;
36
+ import org .apache .commons .lang3 .time .DurationFormatUtils ;
33
37
import org .apache .commons .lang3 .tuple .ImmutablePair ;
34
38
import org .slf4j .Logger ;
35
39
import org .slf4j .LoggerFactory ;
@@ -56,6 +60,30 @@ public static WorkflowServiceStubs createTemporalService(final String temporalHo
56
60
57
61
public static final String DEFAULT_NAMESPACE = "default" ;
58
62
63
+ private static final Duration WORKFLOW_EXECUTION_TTL = Duration .ofDays (7 );
64
+ private static final String HUMAN_READABLE_WORKFLOW_EXECUTION_TTL =
65
+ DurationFormatUtils .formatDurationWords (WORKFLOW_EXECUTION_TTL .toMillis (), true , true );
66
+
67
+ public static void configureTemporalNamespace (WorkflowServiceStubs temporalService ) {
68
+ final var client = temporalService .blockingStub ();
69
+ final var describeNamespaceRequest = DescribeNamespaceRequest .newBuilder ().setNamespace (DEFAULT_NAMESPACE ).build ();
70
+ final var currentRetentionGrpcDuration = client .describeNamespace (describeNamespaceRequest ).getConfig ().getWorkflowExecutionRetentionTtl ();
71
+ final var currentRetention = Duration .ofSeconds (currentRetentionGrpcDuration .getSeconds ());
72
+
73
+ if (currentRetention .equals (WORKFLOW_EXECUTION_TTL )) {
74
+ LOGGER .info ("Workflow execution TTL already set for namespace " + DEFAULT_NAMESPACE + ". Remains unchanged as: "
75
+ + HUMAN_READABLE_WORKFLOW_EXECUTION_TTL );
76
+ } else {
77
+ final var newGrpcDuration = com .google .protobuf .Duration .newBuilder ().setSeconds (WORKFLOW_EXECUTION_TTL .getSeconds ()).build ();
78
+ final var humanReadableCurrentRetention = DurationFormatUtils .formatDurationWords (currentRetention .toMillis (), true , true );
79
+ final var namespaceConfig = NamespaceConfig .newBuilder ().setWorkflowExecutionRetentionTtl (newGrpcDuration ).build ();
80
+ final var updateNamespaceRequest = UpdateNamespaceRequest .newBuilder ().setNamespace (DEFAULT_NAMESPACE ).setConfig (namespaceConfig ).build ();
81
+ LOGGER .info ("Workflow execution TTL differs for namespace " + DEFAULT_NAMESPACE + ". Changing from (" + humanReadableCurrentRetention + ") to ("
82
+ + HUMAN_READABLE_WORKFLOW_EXECUTION_TTL + "). " );
83
+ client .updateNamespace (updateNamespaceRequest );
84
+ }
85
+ }
86
+
59
87
@ FunctionalInterface
60
88
public interface TemporalJobCreator <T extends Serializable > {
61
89
0 commit comments