7

I try to figure out if it's possible to make one Azure webjob and behave it scheduled for say like once per 1 minute and also let it be able to be triggered by a queue. I managed to do both of the requirements separate but not combined in one job.

I know that in order to make them trigger on a queue I need to use JobHost and a Functions class with methods that catch the trigger. Still this blocks the scheduler and only handles triggers

When I omit the JobHost... well then the schedule works perfect. I'm pretty sure that I'm asking a contradiction and just need to make two seperate jobs but maybe one of you faced the same and manage to achieve it.

Casper Broeren
  • 760
  • 2
  • 10
  • 27

1 Answers1

7

I wouldn't use Azure Scheduler/Scheduled Jobs here, since you're already using the SDK. You can use the new TimerTrigger.

What I'd probably do is have two functions. The first function is the function using QueueTrigger and the other is using the new TimerTrigger WebJobs released in v1.1.0. You can see a sample where I do something similar here: https://github.com/christopheranderson/feedbackengine#how-does-it-work

There I have a timer which polls an RSS feed and drops Queue messages, but I can also just drop the Queue messages from another application or, as I did in my scenario, use a WebHook.

Timer Trigger Docs: https://github.com/Azure/azure-webjobs-sdk-extensions#timertrigger

Sample:

// Triggers every minute (every time the clock looks like 00:xx:xx)
public static void CronJob([TimerTrigger("0 * * * * *")] TimerInfo timer, [Queue("Foo")] out string message)
{
    Console.WriteLine("Cron job fired!");
    message = "Hello world!";
}

public static void QueueJob([QueueTrigger("Foo")] string message)
{
    Console.WriteLine(message);
}
Chris Anderson
  • 8,305
  • 2
  • 29
  • 37
  • config.UseTimers(); doesn't seem to exist anymore – TWilly Oct 13 '16 at 23:45
  • 1
    It does. You might not be pulling in the package or adding the proper reference. Maybe a new post with a code sample if you can't figure it out? – Chris Anderson Oct 20 '16 at 22:04
  • 1
    This is in the Microsoft.Azure.WebJobs.Extensions NuGet package not the core WebJobs – Paul Hatcher May 26 '17 at 08:04
  • @ChrisAnderson-MSFT any idea how you could check the status of the triggered message? Basically any way that we could check whether the triggered job is completed successfully or has failed? – akd Nov 03 '17 at 12:21
  • Should probably ask on a new SO question, mate. If you have the dashboard enabled, you'd check the dashboard. If you've switched to App Insights, then just check your logs in App Insights. – Chris Anderson Nov 03 '17 at 18:00