Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and code refactoring to get it ready for durable function support #72

Merged
merged 2 commits into from
Oct 5, 2018

Conversation

daxian-dbw
Copy link
Contributor

@daxian-dbw daxian-dbw commented Oct 5, 2018

Fix #71

  • Use ConvertTo-Json for converting the results returned from the function to JSON. So objects that are wrapped in PSObject won't be a problem anymore.
  • Refactor the code to make it ready for durable function implementation.

The implementation of invoking an orchestration function is made a placeholder in this PR, where it throws NotImplementedException when an orchestration function is triggered.
See RequestProcessor.InvokeOrchestrationFunction.

@daxian-dbw
Copy link
Contributor Author

@tylerl0706 I need to work on top of this refactoring for cleaning up the durable function implementation.
Since it's mainly refactoring and CI has passed, I will merge it now. Take your time to review and comment, and I will address your comments in separate PRs.

@daxian-dbw daxian-dbw merged commit ee8229b into dev Oct 5, 2018
@daxian-dbw daxian-dbw deleted the refactor branch October 5, 2018 22:59
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM :) just some follow ups


}
else
if (parameterMetadata.ContainsKey(binding.Name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now... but we should do the validation to make sure that the param block has all the input bindings.

tracked in #15

}

PSObject returnObject = null;
using (ExecutionTimer.Start(_logger, "Execution of the user's function completed."))
var result = _pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Get-OutputBinding")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change the var to the actual returned type for clarity

/// <summary>
/// Create an object of 'StreamingMessage' as a template, for further update.
/// </summary>
private StreamingMessage NewStreamingMessageTemplate(string requestId, StreamingMessage.ContentOneofCase msgType, out StatusResult status)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewStreamingMessageTemplate should probably be renamed to CreateStreamingMessageTemplate or something else...

if(string.Equals(outBindingName, AzFunctionInfo.DollarReturn, StringComparison.OrdinalIgnoreCase))
{
response.ReturnValue = results[outBindingName].ToTypedData(_powerShellManager);
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for $return are we only suppose to set it to the ReturnValue? Or are we also suppose to set the parameter binding for $return?

cc/ @pragnagopa

@@ -92,7 +93,23 @@ public static object ToObject (this TypedData data)
}
}

public static RpcException ToRpcException (this Exception exception)
private static JsonSerializerSettings setting =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you put this here, but I think it should either be in the function as a const, or at the top of the file since it's a constant.

case JObject dict:
return new Hashtable(dict.ToObject<Hashtable>(), StringComparer.OrdinalIgnoreCase);
case JArray list:
return list.ToObject<object[]>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. I forgot about arrays.

break;
case IDictionary hashtable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come you got rid of hashtable?

return false;
}

if ((str[0] == '{' && str[len - 1] == '}') ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is all of this stuff before the JToken.Parse needed? I would think that JToken.Parse could handle all this.

@@ -26,7 +26,14 @@ public class PowerShellManagerTests
}
}
};
public readonly RpcFunctionMetadata rpcFunctionMetadata = new RpcFunctionMetadata();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function that this is used in gets called multiple times and in that function, you're changing the properties of this object. I think you should just make a new RpcFunctionMetadata inside the function for each invocation instead of mutating the existing one.

@@ -129,8 +146,13 @@ static RpcHttp ToRpcHttp (this HttpResponseContext httpResponseContext)
return rpcHttp;
}

public static TypedData ToTypedData(this object value)
internal static TypedData ToTypedData(this object value, PowerShellManager psHelper)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about having to pass in the psHelper all the time just so that we can reuse the powershell session to run ConvertTo-Json...

Can we just create a constant PowerShell instance in this file that's only used to call ConvertTo-Json?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants