Skip to content

Commit 889521e

Browse files
committed
Code cleanup/resolving minor issues
1 parent fc7728a commit 889521e

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

src/WebJobs.Script.WebHost/HttpException.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,36 @@ namespace Microsoft.Azure.WebJobs.Script.WebHost
1111
{
1212
public class HttpException : Exception
1313
{
14-
private readonly int httpStatusCode;
15-
1614
public HttpException(int httpStatusCode)
1715
{
18-
this.httpStatusCode = httpStatusCode;
16+
StatusCode = httpStatusCode;
1917
}
2018

2119
public HttpException(HttpStatusCode httpStatusCode)
2220
{
23-
this.httpStatusCode = (int)httpStatusCode;
21+
StatusCode = (int)httpStatusCode;
2422
}
2523

2624
public HttpException(int httpStatusCode, string message) : base(message)
2725
{
28-
this.httpStatusCode = httpStatusCode;
26+
StatusCode = httpStatusCode;
2927
}
3028

3129
public HttpException(HttpStatusCode httpStatusCode, string message) : base(message)
3230
{
33-
this.httpStatusCode = (int)httpStatusCode;
31+
StatusCode = (int)httpStatusCode;
3432
}
3533

3634
public HttpException(int httpStatusCode, string message, Exception inner) : base(message, inner)
3735
{
38-
this.httpStatusCode = httpStatusCode;
36+
StatusCode = httpStatusCode;
3937
}
4038

4139
public HttpException(HttpStatusCode httpStatusCode, string message, Exception inner) : base(message, inner)
4240
{
43-
this.httpStatusCode = (int)httpStatusCode;
41+
StatusCode = (int)httpStatusCode;
4442
}
4543

46-
public int StatusCode { get { return this.httpStatusCode; } }
44+
public int StatusCode { get; }
4745
}
4846
}

src/WebJobs.Script.WebHost/WebJobsScriptHostService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
222222

223223
var currentHost = _host;
224224
Task stopTask = Orphan(currentHost, _logger, cancellationToken);
225-
Task result = await Task.WhenAny(stopTask, Task.Delay(TimeSpan.FromSeconds(10)));
225+
Task result = await Task.WhenAny(stopTask, Task.Delay(TimeSpan.FromSeconds(10), cancellationToken));
226226

227227
if (result != stopTask)
228228
{
@@ -346,7 +346,7 @@ internal bool IsHostHealthy(bool throwWhenUnhealthy = false)
346346

347347
private bool ShutdownHostIfUnhealthy()
348348
{
349-
if (ShouldMonitorHostHealth && _healthCheckWindow.GetEvents().Where(isHealthy => !isHealthy).Count() > _healthMonitorOptions.Value.HealthCheckThreshold)
349+
if (ShouldMonitorHostHealth && _healthCheckWindow.GetEvents().Count(isHealthy => !isHealthy) > _healthMonitorOptions.Value.HealthCheckThreshold)
350350
{
351351
// if the number of times the host has been unhealthy in
352352
// the current time window exceeds the threshold, recover by

src/WebJobs.Script/Binding/Extensibility/ScriptBindingContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ public ScriptBindingContext(JObject bindingMetadata)
112112
/// <returns>The metadata value.</returns>
113113
public TValue GetMetadataValue<TValue>(string name, TValue defaultValue = default(TValue))
114114
{
115-
JToken value = null;
116115
try
117116
{
118-
if (Metadata.TryGetValue(name, StringComparison.OrdinalIgnoreCase, out value))
117+
if (Metadata.TryGetValue(name, StringComparison.OrdinalIgnoreCase, out JToken value))
119118
{
120119
return value.Value<TValue>();
121120
}

src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,7 @@ public bool Equals(Type x, Type y)
168168

169169
public int GetHashCode(Type obj)
170170
{
171-
if (obj == null)
172-
{
173-
return 0;
174-
}
175-
176-
return obj.FullName.GetHashCode();
171+
return obj?.FullName?.GetHashCode() ?? 0;
177172
}
178173
}
179174
}

src/WebJobs.Script/Rpc/FunctionRegistration/FunctionDispatcher.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ namespace Microsoft.Azure.WebJobs.Script.Rpc
1919
{
2020
internal class FunctionDispatcher : IFunctionDispatcher
2121
{
22+
private readonly IMetricsLogger _metricsLogger;
23+
private readonly ILoggerFactory _loggerFactory;
2224
private IScriptEventManager _eventManager;
23-
private IMetricsLogger _metricsLogger;
2425
private IEnumerable<WorkerConfig> _workerConfigs;
2526
private CreateChannel _channelFactory;
2627
private ILanguageWorkerChannelManager _languageWorkerChannelManager;
2728
private ConcurrentDictionary<string, LanguageWorkerState> _workerStates = new ConcurrentDictionary<string, LanguageWorkerState>();
2829
private IDisposable _workerErrorSubscription;
2930
private IList<IDisposable> _workerStateSubscriptions = new List<IDisposable>();
30-
private ILoggerFactory _loggerFactory;
3131
private ScriptJobHostOptions _scriptOptions;
3232
private bool disposedValue = false;
3333

@@ -127,8 +127,7 @@ public void Register(FunctionRegistrationContext context)
127127

128128
public void WorkerError(WorkerErrorEvent workerError)
129129
{
130-
LanguageWorkerState erroredWorkerState;
131-
if (_workerStates.TryGetValue(workerError.Language, out erroredWorkerState))
130+
if (_workerStates.TryGetValue(workerError.Language, out LanguageWorkerState erroredWorkerState))
132131
{
133132
erroredWorkerState.Errors.Add(workerError.Exception);
134133
bool isPreInitializedChannel = _languageWorkerChannelManager.ShutdownChannelIfExists(workerError.Language);

src/WebJobs.Script/Rpc/RpcInitializationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal async Task InitializeRpcServerAsync()
5858
{
5959
try
6060
{
61-
_logger.LogInformation("Initializaing RpcServer");
61+
_logger.LogInformation("Initializing RpcServer");
6262
await _rpcServer.StartAsync();
6363
}
6464
catch (Exception grpcInitEx)

0 commit comments

Comments
 (0)