Get call backs on workflow status update and result

How do I start a workflow async and then provide two callback functions, one for status update and one for getting the result? Some Java client side codelet would be great. If callback functions are not supported (ChatGPT says they are), how do I get status update and result async, not waiting blocked? Thanks!

WorkflowClient.execute returns a CompletableFuture, which can be used to wait for workflow completion asynchronously.

My workflow is untyped on the Java side, since the workflows are defined and registered in GoLang. Here it’s referenced with the workflowName “BasicJobWorkflow” only, without its interface. What do I pass in as the proc to WorkflowClient.execute()?

   String workflowName = "BasicJobWorkflow";
    WorkflowOptions options = WorkflowOptions.newBuilder()
            .setWorkflowId(workflowName + System.nanoTime())
            .setRetryOptions(RetryOptions.newBuilder()
                    .setMaximumAttempts(3)
                    .setInitialInterval(Duration.ofSeconds(5))
                    .setBackoffCoefficient(1.0)
                    .build())
            .setTaskQueue("worker1")
            .build();
    WorkflowStub workflow = client.newUntypedWorkflowStub(workflowName, options);

    ProtobufJob.Job job = ProtobufJob.Job.newBuilder().setJobId(123465).build();
    // Start the workflow
    // WorkflowExecution execution = workflow.start(job);
    CompletableFuture<Void> workflowCompletion = WorkflowClient.execute(workflow::?, job);

Got it. The workflow stub itself has async methods.
WorkflowExecution execution = workflow.start(job);
workflow.getResultAsync(ProtobufJob.Job.class).thenAccept( s → {
System.out.println("Result of workflow execution: " + s.getTestScore());
});

Maxim,
Many thanks to your help. How about the second half of the question, how can I can notifications on the status changes of the workflow from pending, to running, and to complete or error? Thanks

Not sure what “pending” workflow means. Once a workflow completes, the future will return either result or failure, so you’ll know to which state it transitioned.

“Pending” means the status a workflow is submitted but not yet being executed by any worker. Once it’s started, it’s “running”, until it’s “completed” or “failed” with errors. My question was if there is any way to get async notification of such workflow status changes. If not, what’s the best alternative to obtain those information in real time? Thanks

You can put an activity that sends the notification at the beginning of the workflow.

Can I create new workflows of “status updates” for the serve side worker to process? Is that a good practise?

I’m not sure I fully understand your proposal. But we have ideas around adding “server side interceptors” to add such functionality generically.