[Java] How to get existing workflow options from a workflow stub?

How can I retrieve an existing WorkflowOptions from a WorkflowStub? I want to terminate a cron and reschedule it with new options, if the options have changed.

Which config options do you need to get from the client side?

from workflow stub you can get a limited set of info such as workflow id and run id.

You can get additional info from DescribeWorkflowExecution api, for example:

DescribeWorkflowExecutionRequest req =
      DescribeWorkflowExecutionRequest.newBuilder()
              .setNamespace(client.getOptions().getNamespace())
              .setExecution(WorkflowExecution.newBuilder()
                      .setWorkflowId("<wfid>")
                      .setRunId("<wfrunid>")
                      .build()).build();
DescribeWorkflowExecutionResponse res =
        service.blockingStub().describeWorkflowExecution(req);
  
res.getWorkflowExecutionInfo()...
res.getExecutionConfig()...

Another approach could be to get the first event in history (WorkflowExecutionStarted event) and get its started event attributes, for example:

GetWorkflowExecutionHistoryRequest req = GetWorkflowExecutionHistoryRequest.newBuilder()
        .setNamespace(client.getOptions().getNamespace())
        .setExecution(WorkflowExecution.newBuilder()
                        .setWorkflowId("<wfid>")
                        .setRunId("<wfrunid>")
                        .build())
        .build();
GetWorkflowExecutionHistoryResponse res =
        service.blockingStub().getWorkflowExecutionHistory(req);

HistoryEvent firstEvent = res.getHistory().getEvents(0);

firstEvent.getWorkflowExecutionStartedEventAttributes().getCronSchedule();
// ...

Thank you @tihomir. Is there anyway to fetch the existing cronSchedule from DescribeWorkflowExecutionResponse? I’m not seeing it.

I do wish this was a little bit easier from an API perspective. It seems like a common use case to conditionally reschedule a cron only if the options have changed.

from DescribeWorkflowExecutionResponse ?

Not currently it seems.

@tihomir FYI, previously I was fetching options from an untyped stub as suggested here:

But I don’t think this is correct. I believe it just points to the locally given options.