Azure / azure-functions-durable-js

JavaScript library for using the Durable Functions bindings
https://www.npmjs.com/package/durable-functions
MIT License
128 stars 47 forks source link

Should we add convenience APIs to quickly register Activity functions? #417

Open hossam-nasr opened 1 year ago

hossam-nasr commented 1 year ago

Based on discussion here.

Current implementation of the SDK for v3 includes two supported ways to register orchestrations and entity functions:

passing the handler directly:

const orchestrator: OrchestrationHandler = function* (context) {
    const outputs = [];
    outputs.push(yield context.df.callActivity(activityName, 'Tokyo'));
    outputs.push(yield context.df.callActivity(activityName, 'Seattle'));
    outputs.push(yield context.df.callActivity(activityName, 'Cairo'));

    return outputs;
};
df.app.orchestration('durableOrchestrator1', orchestrator);

or passing in an options object:

df.app.orchestration('durableOrchestrator1', { handler: orchestrator });

However, this overload isn't done for registering activities. Currently the only way to register activities is by passing in an options object:

const helloActivity: ActivityHandler = (input: string) => {
    return `Hello, ${input}`;
};
df.app.activity('Hello', { handler: helloActivity });

This issue is to discuss whether or not we should also add a convenience overload that allows passing in the handler directly to register an activity, as below:

df.app.activity('Hello', helloActivity); 

The argument against having this overload is that activity functions, unlike orchestrations or entity functions, can accept extra input and output bindings, so there are already other valid parameters that can be passed in the options object than handler (namely extraInputs and extraOutputs). However, it's possible that this is not a very common use-case, and the convenience of having this overload for the cases in which no extra bindings are necessary still justifies adding it.