问题描述
我有一个正在运行的项目,其中包含用于WebJob和存储的非常陈旧的NuGet软件包。大规模升级后,我仅在此块中遇到三个错误:
#Input
n = int(input('Enter n: '))
#Prime = 0
p = []
#Loopidty
for i in range(n):
#Ask user to input x
x = int(input('Enter a Number: '))
#Check if prime
if x < 2:
print('The number is not prime.')
else:
for n in range(2,x - 1):
if x % n == 0:
print('The number is not prime.')
break
else:
print('The number is prime.')
p.append(x)
#Answer
Answer = sum(p) / n
print('The answer is: ',Answer)
错误:
private static void Main()
{
var config = new JobHostConfiguration();
config.Queues.MaxDequeueCount = Convert.ToInt32(ConfigurationManager.AppSettings["MaxDequeueCount"]);
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["MaxPollingInterval"]));
config.Queues.BatchSize = Convert.ToInt32(ConfigurationManager.AppSettings["BatchSize"]); ;
config.NameResolver = new QueueNameResolver();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost();
host.RunAndBlock();
}
所有帮助和问题都显示了.Net Core代码。我在.Net Framework 4.7.2上。我该如何在旧框架中设置此代码?
解决方法
如果要使用Azure WebJob SDK V3,则已删除JobHostConfiguration
和JobHost
。在版本V3中,主机是IHost
的实现。有关更多详细信息,请参阅here和here。此外,请注意,在版本3中,您需要显式安装WebJobs SDK所需的存储绑定扩展。
例如(第3版中的队列触发器)
#Install package Microsoft.Azure.WebJobs.Extensions.Storage 3.x
static async Task Main()
{
var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage(a => {
a.BatchSize = 8;
a.NewBatchThreshold = 4;
a.MaxDequeueCount = 4;
a.MaxPollingInterval = TimeSpan.FromSeconds(15);
});
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}