Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure WebJobs - No functions found - How do I make a trigger-less job?

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?

like image 632
Ray Avatar asked Sep 30 '14 00:09

Ray


People also ask

What is the use of WebJobs in Azure?

Scheduled – We can execute a Scheduled WebJob by writing a CRON Expression. CRON Expressions define the schedule on which we need the WebJob to run. Manual – We can of course trigger a WebJob manually by calling the webhook. Several Azure services can communicate with the WebJobs using the webhook triggers.


2 Answers

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.

like image 174
Victor Hurdugaci Avatar answered Sep 21 '22 11:09

Victor Hurdugaci


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/).

like image 30
Thomas Avatar answered Sep 22 '22 11:09

Thomas