Skip to content

Commit 7fe0b47

Browse files
committed
732 Suspend - action definition updates
1 parent 1e2b926 commit 7fe0b47

File tree

240 files changed

+4236
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+4236
-485
lines changed

sdks/backend/java/component-api/src/main/java/com/bytechef/component/definition/ActionContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public interface ActionContext extends Context {
4646
/**
4747
*
4848
*/
49+
@Deprecated
4950
interface Approval {
5051
/**
5152
*/

sdks/backend/java/component-api/src/main/java/com/bytechef/component/definition/ActionDefinition.java

Lines changed: 212 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
import com.bytechef.component.exception.ProviderException;
2626
import com.bytechef.definition.BaseOutputDefinition.OutputResponse;
27-
import com.bytechef.definition.BaseOutputFunction;
27+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
28+
import java.time.Instant;
2829
import java.util.Collections;
2930
import java.util.List;
3031
import java.util.Map;
@@ -43,6 +44,37 @@ public interface ActionDefinition {
4344
*/
4445
Optional<Boolean> getBatch();
4546

47+
/**
48+
* Retrieves an optional {@link BeforeResumeFunction}, which represents a custom operation to be executed before
49+
* resuming an action in a workflow or process. This function can be utilized for validations, data transformations,
50+
* or other pre-processing tasks related to the continuation of the action.
51+
*
52+
* @return an {@code Optional} containing the {@link BeforeResumeFunction} if defined, or an empty {@code Optional}
53+
* if not present
54+
*/
55+
Optional<BeforeResumeFunction> getBeforeResume();
56+
57+
/**
58+
* Retrieves an optional {@link BeforeSuspendConsumer} that represents a custom operation to be executed before
59+
* suspending an action in a workflow or process. This consumer can be utilized for tasks such as preparing
60+
* suspension parameters or executing custom pre-suspension logic specific to the action.
61+
*
62+
* @return an {@code Optional} containing the {@link BeforeSuspendConsumer} if defined, or an empty {@code Optional}
63+
* if not present
64+
*/
65+
Optional<BeforeSuspendConsumer> getBeforeSuspend();
66+
67+
/**
68+
* Retrieves an optional {@link BeforeTimeoutResumeFunction}, which represents a custom operation to be executed
69+
* before a timeout occurs and allows for resumption of processing with specific parameters. This function serves as
70+
* a mechanism to handle timeout scenarios by potentially modifying processing parameters or performing other
71+
* context-specific actions.
72+
*
73+
* @return an {@code Optional} containing the {@link BeforeTimeoutResumeFunction} if defined, or an empty
74+
* {@code Optional} if not present
75+
*/
76+
Optional<BeforeTimeoutResumeFunction> getBeforeTimeoutResume();
77+
4678
/**
4779
* TODO
4880
*
@@ -85,7 +117,7 @@ public interface ActionDefinition {
85117
*
86118
* @return an optional execute function implementation
87119
*/
88-
Optional<PerformFunction> getPerform();
120+
Optional<? extends BasePerformFunction> getPerform();
89121

90122
/**
91123
*
@@ -99,6 +131,10 @@ public interface ActionDefinition {
99131
*/
100132
Optional<List<? extends Property>> getProperties();
101133

134+
Optional<ResumePerformFunction> getResumePerform();
135+
136+
Optional<SuspendPerformFunction> getSuspendPerform();
137+
102138
/**
103139
*
104140
* @return
@@ -111,6 +147,95 @@ public interface ActionDefinition {
111147
*/
112148
Optional<WorkflowNodeDescriptionFunction> getWorkflowNodeDescription();
113149

150+
/**
151+
*
152+
*/
153+
interface BaseOutputFunction extends com.bytechef.definition.BaseOutputFunction {
154+
155+
}
156+
157+
/**
158+
*
159+
*/
160+
interface BasePerformFunction {
161+
162+
}
163+
164+
/**
165+
* Functional interface representing a consumer to be invoked prior to suspending an action execution. This
166+
* interface is designed to provide custom actions that can be executed before a suspension event occurs. It
167+
* provides parameters related to the current context, suspension details, and options to perform further actions.
168+
*/
169+
@FunctionalInterface
170+
interface BeforeSuspendConsumer {
171+
172+
/**
173+
* Applies a specific action during the execution flow, handling suspension details and resumption parameters.
174+
* This method is invoked with the current action context, allowing for custom logic to be executed before the
175+
* action is suspended for resumption.
176+
*
177+
* @param resumeUrl The URL to be used for resuming the action after suspension.
178+
* @param expiresAt The expiration time indicating how long the suspension is valid.
179+
* @param continueParameters The parameters passed for continuation, containing key-value data for resumption.
180+
* @param context The current action context containing execution data.
181+
* @throws Exception If an error occurs during execution.
182+
*/
183+
void apply(String resumeUrl, Instant expiresAt, Parameters continueParameters, ActionContext context)
184+
throws Exception;
185+
}
186+
187+
/**
188+
* Represents a functional interface for defining a custom operation that is executed before an action resumes in a
189+
* specific workflow or process. The operation takes input data, input parameters, continuation parameters, and an
190+
* action context as arguments, and produces an output encapsulated in a continue {@link Map} instance. This
191+
* functional interface can be leveraged to integrate pre-resume processing logic, such as validations,
192+
* transformations, or enrichments, as part of the action workflow.
193+
*/
194+
@FunctionalInterface
195+
interface BeforeResumeFunction {
196+
197+
/**
198+
* Applies a custom operation before an action resumes in a workflow or process. This method processes the
199+
* provided input data, input parameters, continue parameters, and action context to produce an optional
200+
* continue {@link Map} object. It can be used for operations like validation, data enrichment, or preparation
201+
* before resuming the workflow.
202+
*
203+
* @param data the input data passed to the method for processing
204+
* @param inputParameters the parameters related to the initial invocation of the action
205+
* @param continueParameters the parameters related to the continuation of the action
206+
* @param context the contextual information about the current workflow or process
207+
* @return an optional continue {@link Map} instance containing processed continuation parameters
208+
* @throws Exception if any error occurs during the processing of the operation
209+
*/
210+
Optional<Map<String, ?>> apply(
211+
Object data, Parameters inputParameters, Parameters continueParameters, ActionContext context)
212+
throws Exception;
213+
}
214+
215+
/**
216+
* Functional interface representing a function that is executed before a timeout occurs and allows for resumption
217+
* of processing with specific parameters.
218+
*/
219+
@FunctionalInterface
220+
interface BeforeTimeoutResumeFunction {
221+
222+
/**
223+
* Applies the function using the provided input parameters, continuation parameters, and action context. The
224+
* function may modify the processing based on the inputs and may return specific parameters for further
225+
* processing.
226+
*
227+
* @param inputParameters the parameters provided as input to the function
228+
* @param continueParameters the parameters used for continuation of processing
229+
* @param context the action context which provides additional contextual information for the
230+
* function execution
231+
* @return an {@link Optional} containing continue {@link Map} instance to be used for further actions, or an
232+
* empty {@link Optional} if no result is to be returned
233+
* @throws Exception if an error occurs during function execution
234+
*/
235+
Optional<Map<String, ?>> apply(Parameters inputParameters, Parameters continueParameters, ActionContext context)
236+
throws Exception;
237+
}
238+
114239
/**
115240
*
116241
*/
@@ -133,17 +258,50 @@ List<? extends Option<T>> apply(
133258
}
134259

135260
/**
136-
*
261+
* Represents a specialized output function interface that processes input and connection parameters along with
262+
* additional context to produce a standardized output response. <br>
263+
* This interface extends the {@code BaseOutputFunction} to define a specific method for generating an
264+
* {@code OutputResponse}. <br>
265+
* Implementations of this interface are responsible for handling the logic required to process various inputs and
266+
* contexts, returning a meaningful and structured output.
137267
*/
138268
interface OutputFunction extends BaseOutputFunction {
139269

270+
/**
271+
* Processes the given input parameters, connection parameters, and context to generate an output response.
272+
*
273+
* @param inputParameters the parameters specific to the input data being processed
274+
* @param connectionParameters the parameters required for connection or external resource access
275+
* @param context additional context about the execution environment or process
276+
* @return an {@code OutputResponse} representing the result of the operation, including schema, sample output,
277+
* and optional placeholder
278+
* @throws Exception if an error occurs during the processing
279+
*/
280+
OutputResponse apply(Parameters inputParameters, Parameters connectionParameters, ActionContext context)
281+
throws Exception;
282+
140283
}
141284

142285
/**
143-
*
286+
* Functional interface defining the contract for executing a specific action with given input parameters,
287+
* connection parameters, and action context, and returning a result upon completion. <br>
288+
* The primary purpose of this interface is to provide a flexible mechanism for implementing custom business logic
289+
* that can be executed dynamically within workflows or processes.
144290
*/
145-
interface PerformFunction {
291+
@FunctionalInterface
292+
interface PerformFunction extends BasePerformFunction {
146293

294+
/**
295+
* Applies the specified action using the given input parameters, connection parameters, and action context.
296+
*
297+
* @param inputParameters the input parameters for the action
298+
* @param connectionParameters the parameters related to the connection or configuration
299+
* @param context the context in which the action is executed
300+
* @return the result of the action execution as an Object
301+
* @throws Exception if an error occurs during the execution of the action
302+
*/
303+
Object apply(Parameters inputParameters, Parameters connectionParameters, ActionContext context)
304+
throws Exception;
147305
}
148306

149307
/**
@@ -183,35 +341,56 @@ List<? extends Property.ValueProperty<?>> apply(
183341
}
184342

185343
/**
186-
*
344+
* Represents a functional interface intended for performing a continuation or resume operation with a single
345+
* connection within a workflow or procedural execution context. This interface extends {@code PerformFunction},
346+
* adding support for actions that require input parameters, connection-related parameters, continuation parameters,
347+
* and an action context. <br>
348+
* Implementations of this interface are designed to handle operations that resume from a specific state or context
349+
* during workflow execution.
187350
*/
188-
interface SingleConnectionOutputFunction extends OutputFunction {
351+
@FunctionalInterface
352+
interface ResumePerformFunction {
189353

190354
/**
191-
* @param inputParameters
192-
* @param connectionParameters
193-
* @param context
194-
* @return
195-
*/
196-
OutputResponse apply(Parameters inputParameters, Parameters connectionParameters, ActionContext context)
197-
throws Exception;
355+
* Executes an action using the provided parameters and context. This method is designed for continuation or
356+
* resuming action in a workflow or procedural execution.
357+
*
358+
* @param inputParameters the parameters specific to the operation or input data
359+
* @param connectionParameters the parameters related to the connection or external resource required for
360+
* execution
361+
* @param continueParameters the parameters associated with the continuation process or resume state
362+
* @param context the action context providing access to auxiliary data, event functions, or state
363+
* management facilities
364+
* @return the result of the action execution, which can be any object as per the operation's requirements
365+
* @throws Exception if an error occurs during execution or processing of the action
366+
*/
367+
Object apply(
368+
Parameters inputParameters, Parameters connectionParameters, Parameters continueParameters,
369+
ActionContext context)
198370

371+
throws Exception;
199372
}
200373

201374
/**
202-
*
375+
* Represents a specialized functional interface within the ActionDefinition framework, used for defining
376+
* suspendable action implementations. This interface extends {@link BasePerformFunction} and provides a mechanism
377+
* for suspending actions during their execution.
203378
*/
204379
@FunctionalInterface
205-
interface SingleConnectionPerformFunction extends PerformFunction {
380+
interface SuspendPerformFunction {
206381

207382
/**
383+
* Applies the specified input parameters, connection parameters, and action context to perform an operation
384+
* that results in a suspendable state.
208385
*
209-
* @param inputParameters
210-
* @param connectionParameters
211-
* @param context
212-
* @return
213-
*/
214-
Object apply(Parameters inputParameters, Parameters connectionParameters, ActionContext context)
386+
* @param inputParameters the parameters provided as input for the operation
387+
* @param connectionParameters the parameters required to establish a connection or interaction
388+
* @param context the context in which the action is executed, providing runtime information
389+
* @return a {@link Suspend} object representing the suspendable state, including continuation parameters and
390+
* expiration details
391+
* @throws Exception if an error occurs during the execution of the operation
392+
*/
393+
Suspend apply(Parameters inputParameters, Parameters connectionParameters, ActionContext context)
215394
throws Exception;
216395
}
217396

@@ -250,6 +429,17 @@ interface WorkflowNodeDescriptionFunction {
250429
String apply(Parameters inputParameters, ActionContext context) throws Exception;
251430
}
252431

432+
/**
433+
* Represents a suspend state as part of an action definition. It indicates a temporary suspension with accompanying
434+
* parameters and expiration details.
435+
*
436+
* @param continueParameters a map containing parameters required to continue the suspended action
437+
* @param expiresAt the timestamp indicating when the suspension expires
438+
*/
439+
@SuppressFBWarnings("EI")
440+
record Suspend(Map<String, ?> continueParameters, Instant expiresAt) {
441+
}
442+
253443
/**
254444
* Represents an HTTP response returned by a webhook action.
255445
* <p>

0 commit comments

Comments
 (0)