Skip to content

Commit

Permalink
Fix return output binding logic (Azure#264)
Browse files Browse the repository at this point in the history
* updates to make 2.0 worker 1.0 compatible

* split validation logic so it's both v1 and v2 compatible

* hard-coded solution to camelCase timer trigger while proper fix is out of scope for timeline

* added test

* adding unit test

* properly convert data when defined as output array

* testing both v1 behavior and v2 behavior

* dont code without intellisense

* remove e2e test until have better test on functions host v2 and v3

* fix worker validation logic and warning message on ts changes

* add tests
  • Loading branch information
mhoeger committed Jan 14, 2020
1 parent ab8ad87 commit 08c74de
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 77 deletions.
4 changes: 3 additions & 1 deletion scripts/generateProtos.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function generateProtos() {
.catch(err => console.log(`Could not compile to JavaScript: ${err}`));

// Don't generate with Node.js v12 until resolved: https://github.com/protobufjs/protobuf.js/issues/1275
if (!process.version.startsWith("v12")) {
if (process.version.startsWith("v12") && process.platform === 'win32') {
console.warn("Warning! Could not compile to TypeScript for Node.js 12 and Windows OS. Do not change public interfaces.");
} else {
genTs(allFiles)
.then(data => console.log("Compiled to TypeScript."))
.catch(err => console.log(`Could not compile to TypeScript: ${err}`));
Expand Down
23 changes: 16 additions & 7 deletions src/WorkerChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ export class WorkerChannel implements IWorkerChannel {
// Validate version
let version = process.version;
if (this._v1WorkerBehavior) {
if (version.startsWith("v12."))
{
if (version.startsWith("v12.")) {
systemWarn("The Node.js version you are using (" + version + ") is not fully supported with Azure Functions V2. We recommend using one the following major versions: 8, 10.");
}
} else {
if (version.startsWith("v8."))
{
if (version.startsWith("v8.")) {
let msg = "Incompatible Node.js version. The version you are using (" + version + ") is not supported with Azure Functions V3. Please use one of the following major versions: 10, 12.";
systemError(msg);
throw msg;
Expand Down Expand Up @@ -192,10 +190,22 @@ export class WorkerChannel implements IWorkerChannel {
response.returnValue = toTypedData(result.return);
} else {
let returnBinding = info.getReturnBinding();
response.returnValue = returnBinding ? returnBinding.converter(result.return) : toTypedData(result.return);
// $return binding is found: return result data to $return binding
if (returnBinding) {
response.returnValue = returnBinding.converter(result.return);
// $return binding is not found: read result as object of outputs
} else if (result.return) {
response.outputData = Object.keys(info.outputBindings)
.filter(key => result.return[key] !== undefined)
.map(key => <rpc.IParameterBinding>{
name: key,
data: info.outputBindings[key].converter(result.return[key])
});
}
}
}
if (result.bindings) {
// Data from return supersedes data from context.bindings
if (result.bindings && !response.outputData) {
response.outputData = Object.keys(info.outputBindings)
.filter(key => result.bindings[key] !== undefined)
.map(key => <rpc.IParameterBinding>{
Expand All @@ -207,7 +217,6 @@ export class WorkerChannel implements IWorkerChannel {
} catch (e) {
response.result = this.getStatus(e)
}

this._eventStream.write({
requestId: requestId,
invocationResponse: response
Expand Down
Loading

0 comments on commit 08c74de

Please sign in to comment.