problem : In docker-compose one of services run between temporal server and tctl. So server already exists but namespace is not. As result client connected to temporal server, but worker is not working. How I can handle it ?
We use java client library and a spring /spring boot application. I connect to the namespace at the startup of the application
and I have a set of configuration to
a) auto register the namespace if it does not exists
b) when the auto register is set to false,and if namespace donot exisit, i throw an illegal state exception and do not let the application start at all.
This will work, if you know your namespaces prior hand, but if your namespaces are dynamic, then the only way to figure this is through application log or by raising some alert from your application code.
But in my opinion most common usecases (alomst 90%) you will know your namespaces prior hand.
Here is a code snippet:
public void attemptDomainRegistration(String namespace, TemporalNamespace config,
WorkflowServiceStubs service)
throws Exception {
RegisterNamespaceRequest request = RegisterNamespaceRequest.newBuilder().setName(namespace)
.setHistoryArchivalState(config.isEnableArchival() ? ArchivalState.ARCHIVAL_STATE_ENABLED
: ArchivalState.ARCHIVAL_STATE_DISABLED)
.setDescription("default workflow processor")
.setVisibilityArchivalState(config.isEnableArchival() ? ArchivalState.ARCHIVAL_STATE_ENABLED
: ArchivalState.ARCHIVAL_STATE_DISABLED)
.setWorkflowExecutionRetentionPeriod(com.google.protobuf.Duration.newBuilder()
.setSeconds(Duration.ofDays(config.getWorkflowRetentionPeriodInDays()).getSeconds()))
.build();
if (config.getNamespaceOwnerEmail() != null) {
request = RegisterNamespaceRequest.newBuilder(request).setOwnerEmail(config.getNamespaceOwnerEmail())
.build();
}
int retryCount = 0;
while (true) {
try {
RegisterNamespaceResponse response = service.blockingStub().registerNamespace(request);
log.info("repsone of namespace regisitration is : {}", response.toString());
break;
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode() == Status.Code.ALREADY_EXISTS) {
log.info("Namespace {} exists.. binding to it..", namespace);
break;
}
if (e.getStatus().getCode() == Status.Code.DEADLINE_EXCEEDED
|| e.getStatus().getCode() == Status.Code.UNAVAILABLE) {
// e.printStackTrace();
log.warn("name space registration taking a while.. willl attempt again..");
Thread.sleep(1000);
if (retryCount > 10) {
log.error("could not create namespace, giving up after 10 retries and shutting down.");
// INSTANCE.temporalFactory.shutdownNow();
log.error("giving up namespace registaration...");
break;
// System.exit(1);
}
++retryCount;
}
continue;
} catch (Throwable e) {
log.error("error in starting workflow worker ", e);
System.exit(1);
}
}
}
also , may be this too could work, but havent tried my self
ListNamespacesRequest l = ListNamespacesRequest.newBuilder().build();
ListNamespacesResponse response = service.blockingStub().listNamespaces(l);
any solutions for Go ?
Now we use sleep on starting application, but it isn’t good solution.
Use NamespaceClient.Describe to check if a namespace exists.