13

I have an Webjob associated with the Website that is configured to run continuously and all it does is watches a queue for a message and process it.

My website is in a shared mode and hardly has any traffic at the moment so I have set up dummy service that is requesting the home page every 1 min to keep the website from being shut down as part of this testing, and that seams to work as expected and I can notice that website itself is not shutdown. however this webjob keeps shutting down in about an hour unless I go to the Azure Management portal and look for the webjob status. Moment I go there it starts up again and then shuts down in few minutes to an hour.

the log file for this webjob shows something like this:

[02/13/2015 09:19:45 > 4660f6: INFO] Job host started
[02/13/2015 10:19:41 > 4660f6: SYS INFO] WebJob is still running
[02/13/2015 10:20:35 > 4660f6: SYS INFO] WebJob is stopping due to website shutting down
[02/13/2015 10:20:35 > 4660f6: SYS INFO] Status changed to Stopping
[02/13/2015 10:20:35 > 4660f6: INFO] Job host stopped
[02/13/2015 10:20:35 > 4660f6: SYS INFO] Status changed to Success
[02/13/2015 10:20:35 > 4660f6: SYS INFO] Status changed to Stopped

I can see that my website is still running and returning me the home page, but job itself is stopped.

now when i log in to the management portal to look for the status I can see this in the logs:

[02/13/2015 10:20:35 > 4660f6: SYS INFO] Status changed to Success
[02/13/2015 10:20:35 > 4660f6: SYS INFO] Status changed to Stopped
[02/13/2015 14:56:15 > 4660f6: SYS INFO] Status changed to Starting
[02/13/2015 14:56:17 > 4660f6: SYS INFO] Run script 'WebJobs.exe' with script host - 'WindowsScriptHost'
[02/13/2015 14:56:17 > 4660f6: SYS INFO] Status changed to Running
[02/13/2015 14:56:19 > 4660f6: INFO] Found the following functions:
[02/13/2015 14:56:19 > 4660f6: INFO] WebJobs.NotificationsProgram.ProcessQueueMessage
[02/13/2015 14:56:19 > 4660f6: INFO] WebJobs.NotificationsProgram.PublishNotification
[02/13/2015 14:56:19 > 4660f6: INFO] WebJobs.NotificationsProgram.ProcessMessages
[02/13/2015 14:56:19 > 4660f6: INFO] Job host started

Any ideas as to how can I make sure that the Webjob is active as long as the website is active? or at least to make that the website starts the webjob as well when it comes back to the running state.

UPDATE 1

My webjob itself is a very simple one as shown below:

static void Main(string[] args)
{
    JobHost host = new JobHost();
    host.RunAndBlock();
}

and the trigger functions looks close to like this:

public static void WriteLogPOCO([QueueTrigger("logqueue")] BlobInformation blobInfo, TextWriter logger)
{
    logger.WriteLine("Queue message refers to blob: " + blobInfo.BlobName);
}

is there something I have to do here to indicate that this job should follow the lifecycle of the website, i.e. start up every time the website is started.

UPDATE 2

I tried to look at the Process Explorer and I see one of the three things when the WebJobs are stopped. I don't know how to see the job logs without going to the Management portal, so don't know the actual logs at this point in time.

Sometimes this Sometimes I see this enter image description here

But I am sure that the Job is not running as its not processing any messages from the queue till I go to the management portal.

the pingdom result as shown below which shows that the website itself is running without any break: Ping Dom Result

Regards Kiran

Kiran
  • 2,997
  • 6
  • 31
  • 62

2 Answers2

19

This kind of behavior is expected if you're going to be running in Shared mode as you are. It is recommended that you turn on Always On if you have a continuously running webjob. However, this is a feature of Basic and Standard so you will need to change your mode or rethink your solution.

Also, be aware of these notes made from this link.

enter image description here

enter image description here

Rick Rainey
  • 11,096
  • 4
  • 30
  • 48
  • The documentations suggests that the jobs follow the life cycle of the website itself, so why do I have to move to always on? – Kiran Feb 14 '15 at 05:11
  • To keep your website running and therefore prevent your webjob from stopping. – Rick Rainey Feb 14 '15 at 13:29
  • how can I start all the webjobs on this portal when the website itself starts up.. is that even possible? – Kiran Feb 16 '15 at 11:56
  • If the webjob is stopped because the website is not running, then restarting the website will automatically restart the continuous webjob. Have you tried this? I just verified it again for a Free/Shared website. – Rick Rainey Feb 16 '15 at 14:55
  • I am sure my website is running as I have setup a pingdom to monitor it and its showing that the website is OK, but the webjob itself has a log that says its stopping as website is shutting down but never comes back up. I have updated an example of how my webjob looks above, is there something I am missing there to link it with the website? – Kiran Feb 18 '15 at 03:17
  • The only difference between your sample and the one I verified a couple of days ago is that you have the WebJob SDK in yours. Mine doesn't. But, I don't believe that would make a difference. If you go into Site Control Manager (SCM) for your site and look at process explorer, do you see your WebJob process after your log shows it was stopped? – Rick Rainey Feb 18 '15 at 13:16
  • I checked in the Process Explorer in the SCM and posted the image above of what I see there in the Update 2. Do you spot anything wrong here? – Kiran Feb 19 '15 at 17:45
  • would you have any further suggestion that I can try to find out the issue – Kiran Feb 27 '15 at 11:49
  • I haven't been able to reproduce what you are describing so my guess is it is something within your application. – Rick Rainey Feb 28 '15 at 00:52
  • So the images in Update 2 is not really showing anything unusual right? I was suspecting that the Webjob is registered outside my website as its actually running 2 w3wp.exe where as I have just one website. – Kiran Feb 28 '15 at 12:37
  • I have the same issue with my free website on Azure. The webjob stops working after about 20 minutes. But I'm sure my web application is still running. As Kiran I have continuous http get requests (2 req/min). Very strange behaviour. – Fabrizio Accatino Mar 05 '15 at 21:33
  • 1
    Update for "free" websites. I don't know if it also apply to "shared" websites. "As of March 2014, websites in Free mode can time out after 20 minutes if there are no requests to the scm (deployment) site and the website's portal is not open in Azure. Requests to the actual site will not reset this." Source: http://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/ – Fabrizio Accatino Mar 05 '15 at 21:38
  • @FabrizioAccatino I just came across that too and came back here to update my answer to include this. – Rick Rainey Mar 09 '15 at 18:11
  • 3
    @FabrizioAccatino: I got a workaround to my problem, may be that will help you as well. The requirement is to make sure that we have a call to the scm site and the job starts running. so in my code when i post a message to the queue, I am explicitly calling to scm site using the deployment credential and it starts up my job. Andrzej Turski helped me out with his code as here - http://stackoverflow.com/questions/28904186/how-can-i-keep-my-azure-webjob-running-without-always-on/28923039#28923039 – Kiran Mar 10 '15 at 07:22
0

The webjobs stops because the website is shutting down. In the log you have the following line:

[02/13/2015 10:20:35 > 4660f6: SYS INFO] WebJob is stopping due to website shutting down
Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
  • 1
    I was expecting the job to start when the website comes back up, is that not the case? – Kiran Feb 14 '15 at 05:10