17

I'm new to Azure WebJobs, I've run a sample where a user uploads an image to blob storage and inserts a record into the Queue, then the job retrieves that from the queue as a signal to do something like resizing the uploaded image. Basically in the code the job uses QueueTrigger attribute on a public static method to do all that.

Now I need a job that just does something like inserting a record into a database table every hour, it does not have any type of trigger, it just runs itself. How do I do this?

I tried to have a static method and in it I do the insert to db, the job did start but I got a message saying:

No functions found. Try making job classes public and methods public static.

What am I missing?

Edit After Victor's answer I tried the following,

static void Main()
{
    JobHost host = new JobHost();
    host.Call(typeof(Program).GetMethod("ManualTrigger"));
}

[NoAutomaticTrigger]
public static void ManualTrigger()
{
    // insert records to db
}

but this time I got InvalidOperationException,

'Void ManualTrigger()' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?

2 Answers 2

17

If you don't use any input/output attributes from the WebJobs SDK (QueueTrigger, Blob, Table, etc), you have to decorate the job with the NoAutomaticTrigger Attribute to be recognized by the SDK.

7
  • Thanks Victor for your answer, I tried NoAutomaticTrigger and got an InvalidOperationException, I've updated my question with the code I have, could you help to see what I'm doing wrong please. Thanks a lot!
    – Ray
    Sep 30, 2014 at 2:55
  • 3
    Ah you are right, I just declared "public" on the "class Program", it runs however it shows the msg below for a couple seconds and then the console window just crashes away. Msg: "Found the following function: WebJob1.Program.ManualTrigger Executing: 'Program.ManualTrigger' because This was function waas programmatically called via the host APIs."
    – Ray
    Sep 30, 2014 at 6:00
  • The process will exit unless you call host.RunAndBlock();. Sep 30, 2014 at 6:04
  • Host.Call is similar to invoking a function and then continuing. RunAndBlock will (surprise!) block and keep the program alive Sep 30, 2014 at 15:43
  • 2
    There is one advantage is using the SDK even with no automatic trigger. While the host is running (aka RunAndBlock or host.Start), you see the function in the WebJobs dashboard. That allows you to invoke the function directly from there. Think of host.Call as a fancy MethodInfo.call that gives you dashboard logging Oct 3, 2014 at 23:41
3

You could use the latest WebJobs SDK, which supports triggering job functions on schedule, based on the same CRON expression format. You can use it to schedule your job every hour:

[Disable("DisableMyTimerJob")]
public static void TimerJob([TimerTrigger("00:01:00")] TimerInfo timerInfo, TextWriter log)
{
    log.WriteLine("Scheduled job fired!");
}

Moreover, the WebJobs SDK also has a DisableAttribute that can be applied to functions, that allows you to enable/disable functions based on application settings. If you change the app setting in the Azure Management Portal, the job will be restarted (https://azure.microsoft.com/en-us/blog/extensible-triggers-and-binders-with-azure-webjobs-sdk-1-1-0-alpha1/).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.