Skip to content

Commit

Permalink
Merge pull request #628 from Azure/dev
Browse files Browse the repository at this point in the history
Merging dev into master
  • Loading branch information
soninaren authored Feb 5, 2018
2 parents bdd464c + 8b3158f commit 73bb0e6
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 33 deletions.
10 changes: 10 additions & 0 deletions Functions.Templates/Documentation/cosmosDBTrigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ The settings for an Azure Cosmos DB trigger specifies the following properties a

> Connection strings used for the Lease collection require **write permission**.
The following settings customize the internal Change Feed mechanism and Lease collection usage, and can be set in the `function.json` in the Advanced Editor with the corresponding property names:

- `leaseCollectionPrefix` : When set, it adds a prefix to the leases created in the Lease collection for this Function, effectively allowing two separate Azure Functions to share the same Lease collection by using different prefixes.
- `feedPollDelay` : When set, it defines, in milliseconds, the delay in between polling a partition for new changes on the feed, after all current changes are drained. Default is 5000 (5 seconds).
- `leaseAcquireInterval` : When set, it defines, in milliseconds, the interval to kick off a task to compute if partitions are distributed evenly among known host instances. Default is 13000 (13 seconds).
- `leaseExpirationInterval` : When set, it defines, in milliseconds, the interval for which the lease is taken on a lease representing a partition. If the lease is not renewed within this interval, it will cause it to expire and ownership of the partition will move to another instance. Default is 60000 (60 seconds).
- `leaseRenewInterval` : When set, it defines, in milliseconds, the renew interval for all leases for partitions currently held by an instance. Default is 17000 (17 seconds).
- `checkpointFrequency` : When set, it defines, in milliseconds, the interval between lease checkpoints. Default is always after a successful Function call.
- `maxItemsPerInvocation` : When set, it customizes the maximum amount of items received per Function call.

#### Azure Cosmos DB trigger C# example

#r "Microsoft.Azure.Documents.Client"
Expand Down
2 changes: 1 addition & 1 deletion Functions.Templates/Documentation/httpTrigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
## Example JavaScript code for an HTTP trigger function

We support an [express-like api](https://expressjs.com/en/4x/api.html#res) for JavaScript http triggers.
See supported methods for [context.req](https://github.com/Azure/azure-webjobs-sdk-script/blob/dev/src/WebJobs.Script/azurefunctions/http/request.js) and [context.res](https://github.com/Azure/azure-webjobs-sdk-script/blob/dev/src/WebJobs.Script/azurefunctions/http/response.js).
See supported methods for [context.req](https://github.com/Azure/azure-functions-host/blob/v1.x/src/WebJobs.Script/azurefunctions/http/request.js) and [context.res](https://github.com/Azure/azure-functions-host/blob/v1.x/src/WebJobs.Script/azurefunctions/http/response.js).

```javascript
module.exports = function(context, req) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.6" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.7" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using Microsoft.Azure.Documents;

public static void Run(IReadOnlyList<Document> input, TraceWriter log)
public static void Run(IReadOnlyList<Document> documents, TraceWriter log)
#endif
#if (vsTemplates)
using System.Collections.Generic;
Expand All @@ -21,12 +21,12 @@ public static void Run([CosmosDBTrigger(
databaseName: "DatabaseValue",
collectionName: "CollectionValue",
ConnectionStringSetting = "ConnectionValue",
LeaseCollectionName = "leases")]IReadOnlyList<Document> input, TraceWriter log)
LeaseCollectionName = "leases")]IReadOnlyList<Document> documents, TraceWriter log)
#endif
{
if (input != null && input.Count > 0) {
log.Verbose("Documents modified " + input.Count);
log.Verbose("First document Id " + input[0].Id);
if (documents != null && documents.Count > 0) {
log.Verbose("Documents modified " + documents.Count);
log.Verbose("First document Id " + documents[0].Id);
}
}
#if (vsTemplates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "input",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "input",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function (context, input) {
if (!!input && input.length > 0) {
context.log('Document Id: ', input[0].id);
module.exports = function (context, documents) {
if (!!documents && documents.length > 0) {
context.log('Document Id: ', documents[0].id);
}

context.done();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#if (portalTemplates)
#r "Microsoft.Azure.WebJobs.Extensions.EventGrid"
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
#r "Newtonsoft.Json"

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public static void Run(EventGridEvent eventGridEvent, TraceWriter log)
public static void Run(JObject eventGridEvent, TraceWriter log)
#endif
#if (vsTemplates)
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Company.Function
{
public static class EventGridTriggerCSharp
{
[FunctionName("EventGridTriggerCSharp")]
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, TraceWriter log)
public static void Run([EventGridTrigger]JObject eventGridEvent, TraceWriter log)
#endif
{
log.Info(eventGridEvent.ToString());
log.Info(eventGridEvent.ToString(Formatting.Indented));
}
#if (vsTemplates)
}
Expand Down
21 changes: 20 additions & 1 deletion Functions.Templates/Templates/EventGridTrigger-CSharp/sample.dat
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
Test Message
{
'topic': '/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourcegroups/test/providers/Microsoft.EventHub/namespaces/test',
'subject': 'eventhubs/test',
'eventType': 'captureFileCreated',
'eventTime': '2017-07-14T23:10:27.7689666Z',
'id': '7b11c4ce-1c34-4416-848b-1730e766f126',
'data': {
'fileUrl': 'https://test.blob.core.windows.net/debugging/testblob.txt',
'fileType': 'AzureBlockBlob',
'partitionId': '1',
'sizeInBytes': 0,
'eventCount': 0,
'firstSequenceNumber': -1,
'lastSequenceNumber': -1,
'firstEnqueueTime': '0001-01-01T00:00:00',
'lastEnqueueTime': '0001-01-01T00:00:00'
},
"dataVersion": "",
"metadataVersion": "1"
}
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
Test Message
{
'topic': '/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourcegroups/test/providers/Microsoft.EventHub/namespaces/test',
'subject': 'eventhubs/test',
'eventType': 'captureFileCreated',
'eventTime': '2017-07-14T23:10:27.7689666Z',
'id': '7b11c4ce-1c34-4416-848b-1730e766f126',
'data': {
'fileUrl': 'https://test.blob.core.windows.net/debugging/testblob.txt',
'fileType': 'AzureBlockBlob',
'partitionId': '1',
'sizeInBytes': 0,
'eventCount': 0,
'firstSequenceNumber': -1,
'lastSequenceNumber': -1,
'firstEnqueueTime': '0001-01-01T00:00:00',
'lastEnqueueTime': '0001-01-01T00:00:00'
},
"dataVersion": "",
"metadataVersion": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public static async Task SendGitHubRequest(string url, string requestBody)
{
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("username", "version"));

// Add the GITHUB_CREDENTIALS as an app setting, Value for the app setting is a base64 encoded string in the following format
// "Username:Password" or "Username:PersonalAccessToken"
// Add the GITHUB_CREDENTIALS as an app setting, Value is the "PersonalAccessToken"
// Please follow the link https://developer.github.com/v3/oauth/ to get more information on GitHub authentication
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Environment.GetEnvironmentVariable("GITHUB_CREDENTIALS"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", Environment.GetEnvironmentVariable("GITHUB_CREDENTIALS"));
var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
await client.PostAsync(url, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"language": "PHP",
"trigger": "HttpTrigger",
"category": [
"$temp_category_samples"
"$temp_category_experimental"
],
"categoryStyle": "http",
"enabledInTryMode": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLeve
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;

// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();

// Set name to query string or body data
name = name ?? data?.name;


if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
name = data?.name;
}

return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "IoT Hub (Service Bus Queue)",
"language": "TypeScript",
"category": [
"$temp_category_experimental",
"$temp_category_IoTHub"
],
"categoryStyle": "iot",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "IoT Hub (Service Bus Topic)",
"language": "TypeScript",
"category": [
"$temp_category_experimental",
"$temp_category_IoTHub"
],
"categoryStyle": "iot",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "IoT Hub (Event Hub)",
"language": "TypeScript",
"category": [
"$temp_category_experimental",
"$temp_category_IoTHub"
],
"categoryStyle": "iot",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ You can find more information on the templatting engine at the [wiki page](https

### Generate templates for portal
1. Execute the [getTools](getTools.ps1) script from the root of the repository
2. Build the Functions.Templates/Functions.Templates.csproj via Visual studio or Execute `msbuild Functions.Templates.csproj /p:ItemTemplateVersion=1.0.0 /p:ProjectTemplateVersion=1.0.0 /target:VisualStudioTemplates` from Functions.Templates folder
3. The generated templates should be present in the `Functions.Templates\bin\Portal\Release\Azure.Functions.Templates.Portal` folder
2. Build the Functions.Templates/Functions.Templates.csproj via Visual studio or Execute `msbuild Functions.Templates.csproj` from Functions.Templates folder
3. The generated templates should be present in the `Functions.Templates\bin\Portal\Release\Azure.Functions.Ux.Templates` folder

### Generate templates for Visual Studio
1. Execute the [getTools](getTools.ps1) script from the root of the repository
Expand Down

0 comments on commit 73bb0e6

Please sign in to comment.