Last active
March 26, 2020 23:07
-
-
Save srinayani/b3ba79856e4b845e52f71ea4bcf7effc to your computer and use it in GitHub Desktop.
Upgrading to AzureWebJobs 3.0 sdk Host Not running error from webjob dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.WebJobs; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace Jpprocessor | |
{ | |
public class WebJPProcessor | |
{ | |
var builder = new HostBuilder(); | |
builder.ConfigureLogging(tr => | |
{ | |
tr.SetMinimumLevel(LogLevel.Information); | |
}); | |
builder.ConfigureAppConfiguration((builderContext, cb) => | |
{ | |
cb.AddInMemoryCollection(new Dictionary<string, string>() | |
{ | |
{ "AzureWebJobsDashboard", AzureStorageConnectionString }, | |
{ "AzureWebJobsStorage", AzureStorageConnectionString } | |
}); | |
}); | |
builder.ConfigureWebJobs(b => | |
{ | |
// b.AddAzureStorageCoreServices(); cannot find in the expected packages. | |
b.UseHostId(GetHostId()); // is this the right way to set hostif in 3.0 version? GetHostId() is private method gets machinename | |
b.AddAzureStorage(q => | |
{ | |
q.MaxDequeueCount = 1; | |
q.MaxPollingInterval = TimeSpan.FromSeconds(15); | |
}); | |
}); | |
try | |
{ | |
using (var host = builder.Build()) | |
{ | |
Logger.LogInfo($"{nameof(AzureWebJobProcessor)} starting jobHost with hostid {GetHostId()}"); | |
host.RunAsync().Wait(); | |
Logger.LogInfo($"{nameof(AzureWebJobProcessor)} exiting jobHost"); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Logger.LogError($"{nameof(AzureWebJobProcessor)}/RunAsync WebJob exception: {ex.ToString()} {ex.InnerException.Message}"); | |
} | |
public static void ExecuteAnBUtility( | |
[QueueTrigger("anbutility")] string arguments, | |
TextWriter textLogger) | |
{ | |
lock (syncRoot) | |
{ | |
trackingId = ThreadContext.GenerateTrackingId(); | |
try | |
{ | |
CustomTraceListener.TryAdd(textLogger, trackingId); | |
Trace.WriteLine($"QueueTrigger anbutility got arguments: {arguments}"); | |
AnBUtilityJob.Run(arguments, textLogger); | |
} | |
catch (Exception ex) | |
{ | |
Trace.WriteLine($"Exception:{ex}", traceErrorCategory); | |
throw; | |
} | |
finally | |
{ | |
CustomTraceListener.TryRemove(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment