Schedule in Java SDK

Hi Temporal team,

Does Temporal Java SDK natively supports schedule? Workflows | Temporal Documentation says we can use the gRPC API and method create Schedule. Can you provide more information/examples for this?

@Sowmya

you can use createSchedule method from the WorkflowServiceStubs

E.g.

WorkflowClient client = WorkflowClient.newInstance(service);

    ScheduleSpec.Builder interval =
        ScheduleSpec.newBuilder()
            .addInterval(
                IntervalSpec.newBuilder()
                    .setInterval(com.google.protobuf.Duration.newBuilder().setSeconds(5000).build())
                    .build());
    NewWorkflowExecutionInfo workflowExecutionInfo =
        NewWorkflowExecutionInfo.newBuilder()
            .setWorkflowType(WorkflowType.newBuilder().setName("MyWorkflow").build())
            .setTaskQueue(TaskQueue.newBuilder().setName("taskqueue").build())
            .build();
    client
        .getWorkflowServiceStubs()
        .blockingStub()
        .createSchedule(
            CreateScheduleRequest.newBuilder()
                .setScheduleId("scheduleId")
                .setRequestId("my-request")
                .setNamespace("default")
                .setSchedule(
                    Schedule.newBuilder()
                        .setSpec(interval.build())
                        .setAction(
                            ScheduleAction.newBuilder()
                                .setStartWorkflow(workflowExecutionInfo)
                                .build())
                        .build())
                .build());

I will try to add this to the samples-repo [Feature Request] sample for schedule · Issue #461 · temporalio/samples-java · GitHub

This is being actively worked on here and should be done in not too long.

1 Like

Thanks @antonio.perez for the quick reply. @Chad_Retz , Is there any estimate of when this will be available?

Not exactly. Hopefully soon (i.e. in master in days or weeks, not months).

1 Like

I just now tried the above example, but facing below error:

io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown method CreateSchedule for service temporal.api.workflowservice.v1.WorkflowService
	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156)
	at io.temporal.api.workflowservice.v1.WorkflowServiceGrpc$WorkflowServiceBlockingStub.createSchedule(WorkflowServiceGrpc.java:3643)

Is there something that I’m missing here? Also, where do we specify the workflow that schedule should run? Is it the WorkflowType?

Yes, it is the workflow type,

I ran the code above with java-sdk 1.19.1. Which SDK are you using?

I had 1.15.1 earlier. Upgraded to 1.19.1 but still facing the same error.

that is weird,
can you try cloning the repo and running this example temporal_samples-java/HelloSchedule.java at community_8388 · antmendoza/temporal_samples-java · GitHub ?

Let me know how it goes.

Still same error:

Exception in thread "main" io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown method CreateSchedule for service temporal.api.workflowservice.v1.WorkflowService
	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:271)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:252)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:165)
	at io.temporal.api.workflowservice.v1.WorkflowServiceGrpc$WorkflowServiceBlockingStub.createSchedule(WorkflowServiceGrpc.java:4164)
	at io.temporal.samples.hello.HelloSchedule.main(HelloSchedule.java:59)

May be this is related to my temporal set up for local. I’m using following docker images:

  1. elasticsearch:7.16.3
  2. postgres:13
  3. temporalio/auto-setup:1.16.2
  4. temporalio/admin-tools:1.16.2
  5. temporalio/ui:0.14.1
  6. temporalio/web:1.15.0

I think so @Sowmya

Schedule was added in 1.17 https://github.com/temporalio/temporal/releases/tag/v1.17.0

Can you pull the latest version in your local environment?

Worked with latest versions. Thanks

Hi @antonio.perez ,

We are good to use schedule feature from the below suggested solution in production, right? Wanted to confirm once.

Yes should be ok to use schedules for prod use cases. Would make sure service is on latest version v1.20.3

@antonio.perez Regarding the example that you have posted can you please let me know the following

  1. What happens if two different createSchedule request is made with different scheduleId but same requestId? Will the second submit request throw error or it will be silently ignored?
  2. requestId idempotency is applicable for only successful createSchdule request? I mean let’s say my first createSchedule request with requestId1 fails for some reason then I can retry with same requestId1 ?
  3. In the documentation for Java SDK I can find mention of only cron scheduler? Can you please point me to the documentation where scheduleId, requestId, etc are explained?

Couple of other questions

  1. From Java SDK can I get a list of all schedules?
  2. Can I cancel a Schedule from Java SDK?