4

I just created a new deployment slot for my app, imported the publishing profile to Visual Studio, but after deployment I get this error message:

Error 8: An error occurred while creating the WebJob schedule: No website could be found which matches the WebSiteName [myapp__staging] and WebSiteUrl [http://myapp-staging.azurewebsites.net] supplied.

I have 2 webjobs, a continuous and a scheduled webjob.

I already signed in to the correct Azure account, as stated by this answer.

Will I need to set something else up in order to deploy my app to a staging Deployment Slot with webjobs?

My app is using ASP.NET, if it makes a difference?

Community
  • 1
  • 1
Jeff
  • 11,384
  • 12
  • 77
  • 145

2 Answers2

5

There are a few quirks when using the Azure Scheduler. The recommendation is to use the new CRON support instead. You can learn more about it here and here.

David Ebbo
  • 40,353
  • 7
  • 92
  • 112
  • They do the same thing? – Jeff Nov 04 '15 at 06:46
  • @Jeff They do. You can accomplish the same thing with both. – lopezbertoni Nov 04 '15 at 11:50
  • @lopezbertoni great! So I'd just have to remove the schedule before applying the new CRON stuff? Or is there more to converting an existing webjob to use CRON? – Jeff Nov 04 '15 at 11:51
  • @Jeff Yes, I'll provide an example shortly. – lopezbertoni Nov 04 '15 at 11:56
  • 2
    See https://github.com/davidebbo/ForumScorer for a sample with a Web App and a WebJob that uses CRON scheduling. Note that `webjob-publish-settings.json` has no scheduling information, as that's instead in `settings.job`. You may also need to delete scheduler resources in the Azure portal to clean up. – David Ebbo Nov 04 '15 at 16:08
  • @DavidEbbo When setting `"runMode": "OnDemand"` like your sample, when deploying the WebJob, the Azure Portal has it as **Triggered**. The WebJob was previously set to run using Azure Scheduler. I deleted it, republished it, and still shows as Triggered. The Schedule column has the correct schedule. Is that expected? – SvenAelterman Nov 17 '16 at 15:53
  • 1
    @Speedbird186 yes, scheduled jobs are 'triggered', so that's expected. If it shows the schedule in the portal, you're in good shape. Make sure you have 'Awlays On' enabled on the Web App. – David Ebbo Nov 17 '16 at 17:42
3

Jeff,

As David suggested, you can/should migrate to the new CRON support. Here's an example. The WebJob will be deployed as a continuous WebJob.

Keep in mind that in order to use this you need to install the WebJobs package and extensions that are currently a prerelease. You can get them on Nuget.

Install-Package Microsoft.Azure.WebJobs -Pre Install-Package Microsoft.Azure.WebJobs.Extensions -Pre

Also, as David suggested if you're not using the WebJobs SDK, you can also run this using a settings.job file. He provided an example here.

Program.cs

static void Main()
{
    //Set up DI (In case you're using an IOC container)
    var module = new CustomModule();
    var kernel = new StandardKernel(module);

    //Configure JobHost
    var storageConnectionString = "your_connection_string";
    var config = new JobHostConfiguration(storageConnectionString) { JobActivator = new JobActivator(kernel) };
    config.UseTimers(); //Use this to use the CRON expression.

    //Pass configuration to JobJost
    var host = new JobHost(config);
    // The following code ensures that the WebJob will be running continuously
    host.RunAndBlock();
}

Function.cs

public class Functions
{
    public void YourMethodName([TimerTrigger("00:05:00")] TimerInfo timerInfo, TextWriter log)
    {
        //This Job runs every 5 minutes. 
        //Do work here. 
    }
}

You can change the schedule in the TimerTrigger attribute.

UPDATE Added the webjob-publish-settings.json file

Here's an example of the webjob-publiss-settings.json

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "YourWebJobName",
  "startTime": null,
  "endTime": null,
  "jobRecurrenceFrequency": null,
  "interval": null,
  "runMode": "Continuous"
}
lopezbertoni
  • 3,146
  • 3
  • 36
  • 50
  • Nice - anything I need to change in my webjob JSON file? – Jeff Nov 04 '15 at 12:05
  • 1
    @Jeff Make sure it's set to run as a continuous webjob. I'll update my answer with my JSON file. – lopezbertoni Nov 04 '15 at 12:07
  • Excellent, thank you! So when would one use the Scheduler instead? When using Worker Roles? – Jeff Nov 04 '15 at 12:09
  • 1
    Note that this is a different technique from the `settings.job` CRON I described. `settings.job` is for general WebJobs use (e.g. you can use it to launch a batch file), and this technique is specific the the WebJobs SDK. – David Ebbo Nov 04 '15 at 16:13
  • @DavidEbbo Thanks David for the clarification! Good to know! – lopezbertoni Nov 04 '15 at 17:30
  • @lopezbertoni It might be worth mentioning that to use this code you will need the `Microsoft.Azure.WebJobs.Extensions` NuGet package, which is in *pre-release*. @DavidEbbo So in your example, Azure just invokes the On Demand webjob because of the presence of `settings.job`? – Jeff Nov 04 '15 at 19:32
  • Yes, that's correct. So if you're not already in the SDK world, and just have a plain exe WebJobs (or batch file, PowerShell, etc...), then `settings.job` is the path of least resistance. – David Ebbo Nov 04 '15 at 22:49
  • @DavidEbbo does the CRON expression handling support the (nonstandard) 'L' day marker for the Last day of the month? – JoeBrockhaus Dec 24 '15 at 03:11
  • @JoeBrockhaus not sure. It's using ncrontab (https://code.google.com/p/ncrontab/) for CRON, so whatever that supports will work. – David Ebbo Dec 24 '15 at 18:47