Reputation: 95
I am using Microsoft.azure.webjobs (3.0.0-beta1-10941) in a .net core 2 console app. The aim is to create a azure web job,
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
var host = new JobHost(config);
host.RunAndBlock();
The config.UseTimer() is expected a reference of Microsoft.Azure.WebHost.Host but it needs 2.1.0.0. If i add this by removed beta version 3.0.0-beta1-10941 then host.runandblock() falls over at WindowsAzure.Storage incorrectly deployed install edm, data, or data.services.
I installed the dependencies but still no luck
I have downgraded windowsAzure.Storage to lower than 9 but same issue.
Azure WebJobs NuGet Package Error
Any ideas how to resolved config.UseTimes() in .net core 2.0?
Thanks
Upvotes: 3
Views: 1835
Reputation: 1040
Check documentation. There are solutions for 2.x and 3.x.
For 3.x can be used "b.AddTimers();" Example:
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment(EnvironmentName.Development);
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
b.AddTimers();
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
The time-triggered method: (need to be in a static class)
public static class TimeTrigger
{
// Runs once every 10 seconds
public static void TimerJob([TimerTrigger("00:00:10")] TimerInfo timer)
{
Console.WriteLine("Timer job fired!");
}
}
Upvotes: 0
Reputation: 24569
Any ideas how to resolved config.UseTimes() in .net core 2.0?
In your case you could use the Microsoft.Azure.WebJobs.Extensions Version 3.0.0-beta4. I also do a demo for it. The following is detail steps.
1.Create a net core 2.0 console application.
2.Add the following code in the Program.cs file.
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseTimers();
config.DashboardConnectionString ="storage connectionstring";
config.StorageConnectionString = "storage connectionstring";
var host = new JobHost(config);
host.RunAndBlock();
3. Add the Functions.cs file to the project.
public class Functions
{
public static void CronJob([TimerTrigger("0 */1 * * * *")] TimerInfo timer)
{
Console.WriteLine("Cron job fired!");
}
}
4. Test it on my side.
Upvotes: 7