Schedule not created after being deleted from UI

I implemeted method to create schedule.

  public void schedule(String scheduleId) {
    WorkflowType workflowType = WorkflowType.newBuilder()
            .setName("deleteRejectedResourceAccess")
            .build();
    NewWorkflowExecutionInfo workflowExecutionInfo = NewWorkflowExecutionInfo.newBuilder()
            .setWorkflowId("deleteRejectedResourceAccess")
            .setWorkflowType(workflowType)
            .setTaskQueue(TaskQueue.newBuilder().setName(DELETE_REJECTED_RESOURCE_QUEUE.getQueueName()).build())
            .build();
    ScheduleAction action = ScheduleAction.newBuilder()
            .setStartWorkflow(workflowExecutionInfo).build();
    ScheduleSpec spec = ScheduleSpec.newBuilder().addInterval(
            IntervalSpec.newBuilder()
                    .setInterval(Duration.newBuilder().setSeconds(2).build())
                    .build()).build();
    Schedule schedule = Schedule.newBuilder().setSpec(spec)
            .setAction(action).build();
    CreateScheduleRequest scheduleRequest = CreateScheduleRequest.newBuilder()
            .setRequestId("deleteRejectedResourceAccess")
            .setNamespace(workflowClient.getOptions().getNamespace())
            .setScheduleId(scheduleId)
            .setSchedule(schedule).build();
    workflowClient.getWorkflowServiceStubs().blockingStub()
            .createSchedule(scheduleRequest);
  }

When I hit this function a schedule is created and workflows are initiated every two seconds.
Problem Facing - When I delete a schedule from the UI let’s say Id - deleteRejectedResourceAccess123, and hit the above function again with the same schedule Id, it is not being created. There are no errors as well.

Also please suggest me -

  • My requirement is just to create a schedule once, i.e., when the project starts I want to initiate the schedule if it is not present in that namespace. How to do that?