4
votes

I'm interested in using WebJobs to replace my existing console application. The console application accepts 1 of 5 parameters using /argument style syntax which I currently run using Windows Scheduler on my VM. Each schedule runs the application with a specific argument. Some jobs run every 5 minutes, others run every 6 hours.

When I upload the ZIP containing my console application and its dependencies, I was expecting to be able to supply a command line argument to the application. This doesn't appear to be the case.

If I create a batch file (called Send-Emails.bat) for example and then create a new WebJob called Send-Emails it appears to run the batch file. This is OK, but it would mean that I need to create 5 different WebJobs (again, not a problem) and upload the ZIP 5 times, each with a different batch file that calls the console with the argument.

This last step seems very inefficient, and will quickly become a maintenance nightmare. How to deploy such a system would create problems as well.

This seems like a basic scenario, and one that I would assume the Azure team designed WebJobs for. Has anyone had any success with this? I'd prefer not to alter my code if at all possible, and calling WebJobs from my web application using the API seems to be less than ideal as well.

2

2 Answers

3
votes

Few suggestions:

1
votes

While not a perfect solution because it still involves the scheduler, the solution below has a few advantages. Let me first describe how it works:

You have a single WebJob that uses the WebJobs SDK. Inside this job you have 5 different functions, one for each job that you want. Each of these functions listens to a different Storage Queue. Then, you have 5 schedulers (one per function) that will put a message in the queue corresponding to the function that needs to be invoked.

The advantage of this solution is that you can change the schedule of a function without touching the job code and you have all your jobs/functions in one place.

Here is some sample code for the webjob:

public static void Main()
{
    using (JobHost host = new JobHost())
    {
        host.RunAndBlock();
    }
}

public static void SendEmailFunction(
    [QueueTrigger("send-email-function-trigger")] string message,
    TextWriter log,
{
    log.WriteLine("sending an email");
    // Send email
}

public static void DoSomethingElse(
    [QueueTrigger("do-something-else-trigger")] string message
    TextWriter log)
{
    log.WriteLine("Doing something else");
}

// ... more functions ...

Then if you have a SendEmail scheduler that puts a message in the "send-email-function-trigger", the SendEmailFunction will be triggered.


Another option is to use some environment variables instead of command line arguments. Based on the job name you look in a specific environment variable for the value of the argument.