|
41 | 41 | import io.temporal.api.enums.v1.*;
|
42 | 42 | import io.temporal.api.errordetails.v1.QueryFailedFailure;
|
43 | 43 | import io.temporal.api.failure.v1.ApplicationFailureInfo;
|
| 44 | +import io.temporal.api.failure.v1.CanceledFailureInfo; |
44 | 45 | import io.temporal.api.failure.v1.Failure;
|
45 | 46 | import io.temporal.api.history.v1.*;
|
46 | 47 | import io.temporal.api.nexus.v1.Endpoint;
|
@@ -753,14 +754,26 @@ private void processRequestCancelNexusOperation(
|
753 | 754 | .asRuntimeException();
|
754 | 755 | }
|
755 | 756 |
|
756 |
| - operation.action(Action.REQUEST_CANCELLATION, ctx, null, workflowTaskCompletedId); |
757 |
| - if (isTerminalState(operation.getState())) { |
758 |
| - // Operation canceled before started, so immediately remove operation since no new |
759 |
| - // cancellation task will be generated. |
| 757 | + if (operation.getState() == State.INITIATED) { |
760 | 758 | // TODO: properly support cancel before start once server does
|
| 759 | + ctx.addEvent( |
| 760 | + HistoryEvent.newBuilder() |
| 761 | + .setEventType(EventType.EVENT_TYPE_NEXUS_OPERATION_CANCEL_REQUESTED) |
| 762 | + .setNexusOperationCancelRequestedEventAttributes( |
| 763 | + NexusOperationCancelRequestedEventAttributes.newBuilder() |
| 764 | + .setScheduledEventId(attr.getScheduledEventId()) |
| 765 | + .setWorkflowTaskCompletedEventId(workflowTaskCompletedId)) |
| 766 | + .build()); |
| 767 | + Failure canceled = |
| 768 | + Failure.newBuilder() |
| 769 | + .setMessage("operation canceled before it was started") |
| 770 | + .setCanceledFailureInfo(CanceledFailureInfo.getDefaultInstance()) |
| 771 | + .build(); |
| 772 | + operation.action(Action.CANCEL, ctx, canceled, workflowTaskCompletedId); |
761 | 773 | nexusOperations.remove(scheduleEventId);
|
762 | 774 | ctx.setNeedWorkflowTask(true);
|
763 | 775 | } else {
|
| 776 | + operation.action(Action.REQUEST_CANCELLATION, ctx, null, workflowTaskCompletedId); |
764 | 777 | ctx.addTimer(
|
765 | 778 | ProtobufTimeUtils.toJavaDuration(operation.getData().requestTimeout),
|
766 | 779 | () ->
|
|
0 commit comments