I am trying to return the invocation ID of an Azure function, similar to WebJob's sending the WebJob run ID back in the HTTP Location header. This is so the invoker of my function can check the status periodically to know when it completes.
I see that I must add this id into the response object, and I surmise I need to retrieve it from some context object in the function. This is because when I visit the Functions UI at https://functionapp.scm.azurewebsites.net/azurejobs/#/functions/invocations/a-long-guid
I see a variable named _context with the invocation id. However, I can't seem to access a variable named context, _context, etc in my function.
You can bind to the ExecutionContext by adding a parameter of that type to your function's method (e.g. Run(..., ExecutionContext context)).
That type exposes an InvocationId property that will give you the information you're looking for.
Related
I am trying to pass into a parameter via a event trigger the folder path of the blob storage container #triggerbody().folderpath .
I have created a pipeline parameter called folderPath which is equal to #triggerbody().folderpath
I then created a variable within the pipeline as BusinessUnit and used the variable #{split(pipeline().parameters.folderPath,'/')[3]}
This returns the 'Business Unit'
i.e. BI\DEV\BusinessUnit
What I want to achieve is the ability to use this folderPath (parameter) and BusinessUnit (variable) in other pipelines. However, I am struggling to capture the #triggerbody().folderpath into a global parameter.
Also, there is global variables. The #{split(pipeline().parameters.folderPath,'/')[3]} gives me the correct value as the BusinessUnit variable.
An alternative is to have this as a parameter rather than a variable. However, I can't seem to get the split function to work here.
In ADF we have a Global Parameter which you can access using Manage tab in ADF Studio, however these can only store constants across a Data Factory that can be consumed by a pipeline in any expression.
As you can see below, I have set the Global parameter value to the pipeline parameter that store the value received from the trigger.
In turn, since these parameter's (#pipeline().parameters.folderpath) scope is limited to their pipelines, until you have a parameter with same name and value in other pipelines, this will throw an error! If you have a same parameter and value in another pipeline then there is no need for using a global parameter!
Workaround.....
Using execute pipeline activity to invoke another pipeline in which you want to use this data.
add parameters in the parent pipeline
add parameters in the child pipeline
and now pass the parameters from parents to child while selecting
the child pipeline.
create parameter...
Get value from trigger...
Use/set trigger value in parameter...
Create Parameter in the other pipeline to hold input from parent pipeline...
From parent pipeline in Execute Pipeline activity pass the local parameter value..
use received parameter as necessary....
You can similarly use variable and then pass them to parameter.
Another method could be a web activity that gets the pipeline parameter value and using ADF SDK or REST API, you pass that to the next Execute Pipeline activity. See Parameterizing the Execute Pipeline activity
How can I create a custom system context to pass values from my API to dialogflow which is not dependent on any event.
I tried to put the same in the output context, but it is giving error Invalid Argument as the context name doesn't exist.
Here is the below pseudo code which I am doing (Java),
1. define the contextSettings object by setting credentials provider.
2. Create ContextsClient object using contextSettings object.
3. Create CreateContextRequest object by setting parent and context object.
4. Get the final Context object using ContextsClient.createContext(contextRequest)
5. Set the above context object in queryParameters to pass in DetectIntent Request.
But this is failing in Step # 4, and giving an error as Invalid Argument as the context name is not present under /projects/session
Please help me resolving this issue.
The reason that I want to create custom context is that I need to set values from API to pass to dialogflow and it is independent of Events or a specific flows.
We were able to create custom context in Dialogflow V1 using AIContext class and set the context object in the AIRequest object.
Thanks,
Ron
I am able to resolve the issue. I was not passing fully formed context path while creating the context object.
Context dialogflowContext = Context.newBuilder().setName(
"projects/[project-id]/agent/sessions/" + sessionId + "/contexts/[context-name]")
.setParameters(paramPair).setLifespanCount(1).build();
ExecutionContext.InvocationId vs FunctionFilterContext.FunctionInstanceId
The ExecutionContext in Azure Function has a property InvocationId. In IFunctionInvocationFilter.OnExecutedAsync(FunctionExecutedContext ...) the FunctionExecutedContext has a property FunctionInstanceId, which is defined in its base class FunctionFilterContext.
In the same call, are these two Ids the same?
Are they unique for each call, or for each function instance?
Thanks if anyone can help!
I was confused at first, but these are actually the same thing. They are both showing a unique identifier of function call, so they are the same for the same call, and different between calls.
The docs aren't great in this part, but you can compare Retrieving information about the currently running function
Provides the invocation ID, uniquely identifying the current invocation
with FunctionExceptionContext source code
The instance ID for the function invocation
I actually ran a test and both properties gave me the same Guid.
I have a C# WebJob that uses QueueTrigger with a custom INameResolver to look up queue names from the application settings. This part is working as expected, but now within the method body, I need to know the name of the queue from which the triggering message was received. Ideally, I'd like to just be able to add a specially-named string parameter on my method which would be populated with the triggering queue name by the WebJobs SDK, but the documentation doesn't mention any such bindable parameter.
Is there another way to accomplish this, preferrably without hardcoding the queue name/pattern in two locations (i.e. once in the QueueTrigger attribute and again inside the method body) or writing custom string-parsing code to manually invoke my INameResolver for %patterns%?
You could add an additional parameter to your function to bind to the queue like so:
public static void MyFunction(
[QueueTrigger("%name%")] string message,
[Queue("%name%")] CloudQueue queue)
{
string queueName = queue.Name;
}
An alternative is as you suggested - make your custom INameResolver instance available to your job function (e.g. via DI) and just call resolver.Resolve to get the name.
can somebody please explain what is the difference between the following mechanisms of passing arguments: by value, by result, by result-value, with examples if possible, thanks in advance
For general info see Evaluation strategy.
For example code you can check HERE.
Also C# language specification can be useful :
5.1.4 Value parameters
A parameter declared without a ref or
out modifier is a value parameter. A
value parameter comes into existence
upon invocation of the function member
(method, instance constructor,
accessor, or operator) or anonymous
function to which the parameter
belongs, and is initialized with the
value of the argument given in the
invocation. A value parameter normally
ceases to exist upon return of the
function member or anonymous function.
However, if the value parameter is
captured by an anonymous function
(§7.15), its life time extends at
least until the delegate or expression
tree created from that anonymous
function is eligible for garbage
collection. For the purpose of
definite assignment checking, a value
parameter is considered initially
assigned.
5.1.5 Reference parameters
A parameter declared with a ref
modifier is a reference parameter. A
reference parameter does not create a
new storage location. Instead, a
reference parameter represents the
same storage location as the variable
given as the argument in the function
member or anonymous function
invocation. Thus, the value of a
reference parameter is always the same
as the underlying variable. The
following definite assignment rules
apply to reference parameters. Note
the different rules for output
parameters described in §5.1.6.
A variable must be definitely assigned
(§5.3) before it can be passed as a
reference parameter in a function
member or delegate invocation.
Within a function member or anonymous function, a reference
parameter is considered initially
assigned.
Within an instance method or instance
accessor of a struct type, the this
keyword behaves exactly as a reference
parameter of the struct type (§7.6.7).
5.1.6 Output parameters
A parameter declared with an out
modifier is an
output parameter. An output parameter
does not create a new storage
location. Instead, an output parameter
represents the same storage location
as the variable given as the argument
in the function member or delegate
invocation. Thus, the value of an
output parameter is always the same as
the underlying variable. The following definite
assignment rules apply to output
parameters. Note the different rules
for reference parameters described in
§5.1.5.
A variable need not be definitely assigned before it can be passed as
an output parameter in a function
member or delegate invocation.
Following the normal completion of a function member or delegate
invocation, each variable that was
passed as an output parameter is
considered assigned in that execution
path.
Within a function member or anonymous function, an output
parameter is considered initially
unassigned.
Every output parameter of a function member or anonymous
function must be definitely
assigned (§5.3) before the function
member or anonymous function
returns normally.
Within an instance constructor of a
struct type, the this keyword behaves
exactly as an output parameter of the
struct type (§7.6.7).
See C++. The Complete Reference Guide. Herbert Shildt. Third Edition. 139 page.
"Call by value. This method copies the value of an argument into the formal parameter of the subroutine. In this case, changes made to the parameter have no effect on the argument."
"Call by reference is the second way of passing arguments to a subroutine. In this
method, the address of an argument is copied into the parameter. Inside the subroutine,
the address is used to access the actual argument used in the call. This means that
changes made to the parameter affect the argument."
...