Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Web Job - Data Processing

In VS I've created an Azure Web Job. I see a boiler plate method:

    static void Main()
    {
        var host = new JobHost();
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
    }

Also a function method:

    // This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.
    public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
    {
        log.WriteLine(message);
    }

Cool... however I don't want to use Azure Queue or blog storage. I don't need to pass in any data as arguments or trigger it.

I simply want a job that will run every hour and do some data processing. Specially hit a 3rd party API and load some data into my Azure DB.

What am I missing here?

EDIT

Should I just be using a vanilla console app in this situation and publish it as an "Azure Web Job" ?

like image 313
aherrick Avatar asked Jul 04 '26 11:07

aherrick


1 Answers

You should just use a vanilla console app and deploy that as an Azure Web Job. See the steps below:

  1. Right-click the web project in Solution Explorer, and then click Add > Existing Project as Azure WebJob. The Add Azure WebJob dialog box appears.
  2. In the Project name drop-down list, select the Console Application project to add as a WebJob.
  3. Complete the Add Azure WebJob dialog, and then click OK.
  4. The Publish Web wizard appears. If you don't want to publish immediately, close the wizard. The settings that you've entered are saved for when you do want to deploy the project.

Source with screenshots: https://azure.microsoft.com/nl-nl/documentation/articles/websites-dotnet-deploy-webjobs/#convert

You can find more information about this here: https://azure.microsoft.com/nl-nl/documentation/articles/websites-dotnet-deploy-webjobs/.

On this page you can also read that a console application can be used as an Azure Web Job by adding the Microsoft.Web.WebJobs.Publish NuGet package and a webjob-publish-settings.json.

Example webjob-publish-settings.json:

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "WebJob1",
  "startTime": "2014-06-23T00:00:00-08:00",
  "endTime": "2014-06-27T00:00:00-08:00",
  "jobRecurrenceFrequency": "Minute",
  "interval": 5,
  "runMode": "Scheduled"
}

When you want to add this Azure Web Job to an existing Azure Web App (website) project you can link the webjob by adding a webjobs-list.json file to the website project.

Example webjobs-list.json:

{
  "$schema": "http://schemastore.org/schemas/json/webjobs-list.json",
  "WebJobs": [
    {
      "filePath": "../ConsoleApplication1/ConsoleApplication1.csproj"
    },
    {
      "filePath": "../WebJob1/WebJob1.csproj"
    }
  ]
}
like image 75
Wessel Kranenborg Avatar answered Jul 07 '26 00:07

Wessel Kranenborg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!