Skip to content

Commit c7aa9af

Browse files
committed
Revving version to 0.7 and a few other fixes
1 parent 33eab03 commit c7aa9af

File tree

8 files changed

+41
-30
lines changed

8 files changed

+41
-30
lines changed

WebJobs.Script.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<SkipStrongNamesXml>tools\SkipStrongNames.xml</SkipStrongNamesXml>
88
<PublishPath Condition=" '$(PublishPath)' == '' ">bin</PublishPath>
99
<BuildNumber Condition=" '$(BuildNumber)' == '' ">0</BuildNumber>
10-
<SiteExtensionVersion>0.6.$(BuildNumber)</SiteExtensionVersion>
10+
<SiteExtensionVersion>0.7.$(BuildNumber)</SiteExtensionVersion>
1111
<SiteExtensionBasePath>$(PublishPath)\Packages\SiteExtension</SiteExtensionBasePath>
1212
<SiteExtensionPath>$(SiteExtensionBasePath)\$(SiteExtensionVersion)</SiteExtensionPath>
1313
<ExtensionXml>src\SiteExtension\extension.xml</ExtensionXml>

sample/HttpTrigger-CSharp-CustomRoute/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "info",
66
"direction": "in",
77
"methods": [ "get" ],
8-
"route": "csharp/products/{category:alpha}/{id:int}"
8+
"route": "csharp/products/{category:alpha}/{id:int?}"
99
},
1010
{
1111
"type": "http",

sample/HttpTrigger-CSharp-CustomRoute/run.csx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ using Microsoft.Azure.WebJobs.Host;
88
public class ProductInfo
99
{
1010
public string Category { get; set; }
11-
public int Id { get; set; }
11+
public int? Id { get; set; }
1212
}
1313

14-
public static ProductInfo Run(ProductInfo info, string category, int id, TraceWriter log)
14+
public static ProductInfo Run(ProductInfo info, string category, int? id, TraceWriter log)
1515
{
1616
log.Info($"ProductInfo: Category={category} Id={id}");
1717
log.Info($"Parameters: category={category} id={id}");

src/WebJobs.Script/Binding/Http/HttpTriggerAttributeBindingProvider.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ internal static void ApplyBindingData(object target, IDictionary<string, object>
201201
propertyHelper.Property.CanWrite)
202202
{
203203
object value = pair.Value;
204-
if (value != null && value.GetType() != propertyHelper.Property.PropertyType)
204+
Type targetType = propertyHelper.Property.PropertyType;
205+
if (value != null && value.GetType() != targetType)
205206
{
206-
value = Convert.ChangeType(value, propertyHelper.Property.PropertyType);
207+
// if the type is nullable, we only need to convert to the
208+
// correct underlying type
209+
targetType = Nullable.GetUnderlyingType(targetType) ?? targetType;
210+
value = Convert.ChangeType(value, targetType);
207211
}
208212
propertyHelper.SetValue(target, value);
209213
}
@@ -250,6 +254,9 @@ internal static async Task<IReadOnlyDictionary<string, object>> GetRequestBindin
250254
bindingDataContract.TryGetValue(pair.Key, out type) &&
251255
value.GetType() != type)
252256
{
257+
// if the type is nullable, we only need to convert to the
258+
// correct underlying type
259+
type = Nullable.GetUnderlyingType(type) ?? type;
253260
value = Convert.ChangeType(value, type);
254261
}
255262

src/WebJobs.Script/Content/Script/functions.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function createFunction(f) {
7070
delete context._inputs;
7171

7272
var result = f.apply(null, inputs);
73-
if (result && typeof result.then === 'function') {
73+
if (result && util.isFunction(result.then)) {
7474
context._promise = true;
7575
result.then((result) => context.done(null, result))
7676
.catch((err) => context.done(err));
@@ -88,22 +88,19 @@ function getEntryPoint(f, context) {
8888
}
8989
else if (Object.keys(f).length == 1) {
9090
// a single named function was exported
91-
f = f[Object.keys(f)[0]];
91+
var name = Object.keys(f)[0];
92+
f = f[name];
9293
}
9394
else {
9495
// finally, see if there is an exported function named
9596
// 'run' or 'index' by convention
96-
f = f['run'] || f['index'];
97+
f = f.run || f.index;
9798
}
9899
}
99-
else if (!util.isFunction(f)) {
100-
// the module must export an object or a function
101-
f = null;
102-
}
103100

104-
if (!f) {
101+
if (!util.isFunction(f)) {
105102
throw "Unable to determine function entry point. If multiple functions are exported, " +
106-
"you must indicate the entry point, either by naming it 'run', or by naming it " +
103+
"you must indicate the entry point, either by naming it 'run' or 'index', or by naming it " +
107104
"explicitly via the 'entryPoint' metadata property.";
108105
}
109106

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ internal void AddFunctionError(string functionName, string error)
171171

172172
protected virtual void Initialize()
173173
{
174+
string hostLogPath = Path.Combine(ScriptConfig.RootLogPath, "Host");
175+
string debugSentinelFileName = Path.Combine(hostLogPath, ScriptConstants.DebugSentinelFileName);
176+
this.LastDebugNotify = File.GetLastWriteTime(debugSentinelFileName);
177+
174178
IMetricsLogger metricsLogger = ScriptConfig.HostConfig.GetService<IMetricsLogger>();
175179
if (metricsLogger == null)
176180
{
@@ -189,20 +193,13 @@ protected virtual void Initialize()
189193
File.WriteAllText(hostConfigFilePath, "{}");
190194
}
191195

192-
if (ScriptConfig.HostConfig.IsDevelopment)
196+
if (ScriptConfig.HostConfig.IsDevelopment || InDebugMode)
193197
{
198+
// If we're in debug/development mode, use optimal debug settings
194199
ScriptConfig.HostConfig.UseDevelopmentSettings();
195200
}
196-
else
197-
{
198-
// TEMP: Until https://github.com/Azure/azure-webjobs-sdk-script/issues/100 is addressed
199-
// we're using some presets that are a good middle ground
200-
ScriptConfig.HostConfig.Queues.MaxPollingInterval = TimeSpan.FromSeconds(10);
201-
ScriptConfig.HostConfig.Singleton.ListenerLockPeriod = TimeSpan.FromSeconds(15);
202-
}
203201

204202
string json = File.ReadAllText(hostConfigFilePath);
205-
206203
JObject hostConfig;
207204
try
208205
{
@@ -251,10 +248,6 @@ protected virtual void Initialize()
251248
TraceWriter = new ConsoleTraceWriter(hostTraceLevel);
252249
}
253250

254-
string hostLogPath = Path.Combine(ScriptConfig.RootLogPath, "Host");
255-
string debugSentinelFileName = Path.Combine(hostLogPath, ScriptConstants.DebugSentinelFileName);
256-
this.LastDebugNotify = File.GetLastWriteTime(debugSentinelFileName);
257-
258251
_debugModeFileWatcher = new FileSystemWatcher(hostLogPath, ScriptConstants.DebugSentinelFileName)
259252
{
260253
EnableRaisingEvents = true

test/WebJobs.Script.Tests/SamplesEndToEndTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,17 @@ public async Task HttpTrigger_CSharp_CustomRoute_ReturnsExpectedResponse()
353353
string json = await response.Content.ReadAsStringAsync();
354354
var product = JObject.Parse(json);
355355
Assert.Equal("electronics", (string)product["Category"]);
356-
Assert.Equal(123, (int)product["Id"]);
356+
Assert.Equal(123, (int?)product["Id"]);
357+
358+
// now try again without specifying optional id parameter
359+
uri = $"api/csharp/products/electronics?code={functionKey}";
360+
request = new HttpRequestMessage(HttpMethod.Get, uri);
361+
response = await this._fixture.HttpClient.SendAsync(request);
362+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
363+
json = await response.Content.ReadAsStringAsync();
364+
product = JObject.Parse(json);
365+
Assert.Equal("electronics", (string)product["Category"]);
366+
Assert.Null((int?)product["Id"]);
357367

358368
// test a constraint violation (invalid id)
359369
uri = $"api/csharp/products/electronics/1x3?code={functionKey}";

test/WebJobs.Script.Tests/TestScripts/Node/functions.tests.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ describe('functions', () => {
7676
expect(run).to.be.true;
7777
});
7878

79-
it('throws if no function', () => {
79+
it('throws if not a function', () => {
8080
var func = functions.createFunction(1);
81+
expect(() => func(context)).to.throw(/Unable to determine function entry point.*/);
82+
});
8183

84+
it('throws if object does not contain a function', () => {
85+
var func = functions.createFunction({ run: 1 });
8286
expect(() => func(context)).to.throw(/Unable to determine function entry point.*/);
8387
});
8488
});

0 commit comments

Comments
 (0)