Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expose webjobs functions to dashboard without azure storage

In this question there's an example on how to use a webjob that can perform some background operations without interacting with azure table storage.

I tried to replicate the code in the answer but it's throwing the following error:

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

In this link they have a similar error and in one of the answers it says that this was fixed in the 0.4.1-beta release. I'm running the 0.5.0-beta release and I'm experiencing the error.

Here's a copy of my code:

class Program
{
    static void Main()
    {
        var config = new JobHostConfiguration(AzureStorageAccount.ConnectionString);
        var host = new JobHost(config);

        host.Call(typeof(Program).GetMethod("ScheduleNotifications"));

        host.RunAndBlock();
    }

    [NoAutomaticTrigger]
    public static void ScheduleNotifications()
    {
        //Do work
    }
}

I want to know if I'm missing something or is this still a bug in the Webjobs SDK.

Update: Per Victor's answer, the Program class has to be public.

Working code:

public class Program
{
    static void Main()
    {
        var config = new JobHostConfiguration(AzureStorageAccount.ConnectionString);
        var host = new JobHost(config);

        host.Call(typeof(Program).GetMethod("ScheduleNotifications"));

        host.RunAndBlock();
    }

    [NoAutomaticTrigger]
    public static void ScheduleNotifications()
    {
        //Do work
    }
}
like image 320
lopezbertoni Avatar asked Sep 15 '14 00:09

lopezbertoni


1 Answers

Unless you use a custom type locator, a function has to satisfy all conditions below:

  • it has to be public
  • it has to be static
  • it has to be non abstract
  • it has to be in a non abstract class
  • it has to be in a public class

Your function doesn't meet the last condition. If you make the class public it will work.

Also, if you use webjobs sdk 0.5.0-beta and you run a program with only the code in your example, you will see a message saying that no functions were found.

like image 186
Victor Hurdugaci Avatar answered Nov 16 '22 02:11

Victor Hurdugaci