6

I'm trying to run WebJob as a console app, It works When I add RunOnStartup = true, but I need that it works just with TimerTrigger.

this is my code

public static void Main()
{
  JobHostConfiguration config = new JobHostConfiguration();
  config.UseTimers();
  JobHost host = new JobHost(config);
  host.RunAndBlock();
} 

public static void TimerJob([TimerTrigger("0 0 8 * * *")] TimerInfo timerInfo)
{
    Console.WriteLine("Job Work");
}

What do I need to make this code work?

srd98
  • 623
  • 1
  • 6
  • 12
  • 1
    What doesn't work specifically? You've set up a schedule that will run once a day at 8 AM, so it might be that it's not 8 AM yet? Recommend turning on Verbose logging locally - the JobHost will then print the execution schedule to the Console on startup, so you can see when it will next run. – mathewc Jan 07 '16 at 23:41
  • 1
    You can turn on Verbose console logging via `config.Tracing.ConsoleLevel` – mathewc Jan 07 '16 at 23:59
  • 1
    I added `config.Tracing.ConsoleLevel = System.Diagnostics.TraceLevel.Verbose; ` And it return this : "The next 5 occurrences of the schedule will be: 1/8/2016 8:00:00 PM" However the method never run – srd98 Jan 08 '16 at 21:32
  • Sorry, Return "The next 5 occurrences of the schedule will be: 1/8/2016 8:00:00 AM" – srd98 Jan 08 '16 at 21:40

3 Answers3

3

This behavior was due to an issue in TimerTrigger which has been fixed in the v1.0.1 release that is now live on Nuget.

The issue was that we were using UTC time internally when scheduling occurrences, rather than Local time as you'd expect. While this could cause confusion when running locally, your job would still run correctly on schedule in Azure.

However, this issue has been fixed now.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • I am using v1.0.1 but still I am having the same issue, I have Indian time and in Azure, we have swiss time. – Jenish Zinzuvadiya Nov 21 '16 at 08:09
  • If you're having issues, I recommend you log a bug in our repo [here](https://github.com/Azure/azure-webjobs-sdk-extensions/issues) with complete repro details. You might also try moving to v1.1.2 or even our latest Beta2 prerelease version, all of which contain lots of bug fixes. – mathewc Nov 21 '16 at 16:16
3

This might not be the answer to your specific problem but it answers the very same question. I noticed that it wont find TimerTrigger functions in the Program class. When running it i just get the

Development settings applied

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

Job host started

After putting them in Function class it triggered just fine.

Crypth
  • 1,576
  • 18
  • 32
  • 3
    This answer actually doesn't solve the original question, albeit directed me to the reason why my triggers were not executing. The Program class has to be made public if you want to define your functions there. By default, if you just create fresh console application, the Program class is private... – Rafal Zajac Jun 13 '16 at 16:33
2

First of all, add the JobHostConfiguration Tracing as described here in the Local Development section. Otherwise you won't see the Console text. If you are running locally, you can always set a breakpoint too.

Keep also in mind that the TimerTrigger uses the Web App Timezone when running on Azure or your computer Timezone when running locally. To define the Web App timezone, follow these steps.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47