我怎样才能保持我的Azure WebJob运行没有"始终在" [英] How can I keep my Azure WebJob running without "Always On"

查看:536
本文介绍了我怎样才能保持我的Azure WebJob运行没有"始终在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连续webjob 与网站相关的和我正在运行的网站上的共享模式即可。我不想去为Always On选择,因为有我的应用程序的实际需要。我只是要处理的消息时,调用到我的网站的。

I have a continous webjob associated with a website and I am running that website on the Shared mode. I don't want to go to Always On option as there is no real need for my application. I only want to process the message when the calls are made to my website.

我的问题是,这项工作一直几分钟后停止即使我不断地打电话伪保活方法在我的网站每5一刻,发布消息到由该webjob监视的队列。

My issue is that the job keeps stopping after few minutes even though I am continuously calling a dummy keep alive method on my website at every 5 minute that posts a message to the queue that is monitored by that webjob.

我webjob是使用具有code这样的WebJob SDK构建了一个简单的控制台应用程序

My webjob is a simple console application built using the WebJob SDK that has a code like this

JobHost host = new JobHost(new JobHostConfiguration(storageConnictionSttring));
host.RunAndBlock();

和消息处理函数看起来象下面这样:

and the message processing function looks like below:

public static void ProcessKeepAliveMessages([QueueTrigger("keepalive")] KeepAliveTrigger message)
{
    Console.WriteLine("Keep Alive message called on :{0}", message.MessageTime);
}

有关工作的消息日志基本上说是

The message log for the job basically says says

[03/05/2015 18:51:02 > 4660f6: SYS INFO] WebJob is stopping due to website shutting down

如果出现这种情况了,我不介意,但是当网站与下一次调用开始永葆时,webjob未启动。所有的消息都排队,直到我去管理仪表板或SCM门户如下图所示。

I don't mind if that happen this way, but when the website starts with the next call to keep alive, the webjob is not started. All the messages are queued till I go to the management dashboard or the SCM portal as shown below

https://mysite.scm.azurewebsites.net/api/continuouswebjobs

我可以看到这样的状况:

I can see the status like this:

[{"status":"Starting","detailed_status":"4660f6 - Starting\r\n","log_url":"https://mysite.scm.azurewebsites.net/vfs/data/jobs/continuous/WebJobs/job_log.txt","name":"WebJobs","run_command":"mysite.WebJobs.exe","url":"https://mysite.scm.azurewebsites.net/api/continuouswebjobs/WebJobs","extra_info_url":"https://mysite.scm.azurewebsites.net/azurejobs/#/jobs/continuous/WebJobs","type":"continuous","error":null,"using_sdk":true,"settings":{}}]

我真的AP preciate如果有人能帮助我明白是怎么回事错在这里。

I would really appreciate if someone can help me understand what is going wrong here.

推荐答案

我碰到类似的问题。我有一个网站(共享模式)和关联webjob(连续式)。综观webjob日志,我发现作业进入后约15分钟停止状态。活动和停止的反应来触发消息。这似乎矛盾的连续工作理念的概念,但是,很显然,把它真正运行连续你要订阅付费网站。你得到你所支付...

这是说,我的网站需要使用只有大约每隔几天,并在共享模式下运行非常有意义。我不介意,该网站需要一些额外的时间来上手 - 只要它会自动重新启动。与webjob的问题是,一旦停止它本身不会重新启动。所以,我的目标是与该网站重新启动它。

我注意到,仅仅看一下从Azure管理门户的webjob启动它。根据这一思路,我发现,获取webjob性能就足以将其切换到运行状态。唯一的技巧就是如何以编程方式获取性能,使重新启动网站也将重新启动webjob。

由于获取webjob属性调用必须进行身份验证,第一步是到Azure管理门户和下载网站发布配置文件。在发布配置文件,你可以找到的身份验证凭据:用户名(通常是$<&WEBSITE_NAME GT;)和userPWD(密码哈希)。复制下来。

下面是会得到webjob性能和唤醒它(如果尚未运行)功能:

I've run into a similar problem. I have a website (shared mode) and an associated webjob (continuous type). Looking at webjob logs, I found that the job enters stopped state after about 15 min. of inactivity and stops reacting to trigger messages. It seems contradictory to the concept of continuous job concept but, apparently, to get it running truly continuously you have to subscribe to a paid website. You get what you pay for...

That said, my website needs to be used only about every few days and running in a shared mode makes perfect sense. I don't mind that the site needs a bit extra time to get started - as long as it restarts automatically. The problem with the webjob is that once stopped it won't restart by itself. So, my goal was to restart it with the website.

I have noticed that a mere look at the webjob from Azure Management Portal starts it. Following this line of thinking, I have found that fetching webjob properties is enough to switch it to the running state. The only trick is how to fetch the properties programmatically, so that restarting the website will also restart the webjob.

Because the call to fetch webjob properties must be authenticated, the first step is to go to Azure Management Portal and download the website publishing profile. In the publishing profile you can find the authentication credentials: username (usually $<website_name>) and userPWD (hash of the password). Copy them down.

Here is a function that will get webjob properties and wake it up (if not yet running):

class Program
{
    static void Main(string[] args)
    {
        string websiteName = "<website_name>";
        string webjobName = "<webjob_name>";
        string userName = "<from_publishing_profile>";
        string userPWD = "<from_publishing_profile>";
        string webjobUrl = string.Format("https://{0}.scm.azurewebsites.net/api/continuouswebjobs/{1}", websiteName, webjobName);
        var result = GetWebjobState(webjobUrl, userName, userPWD);
        Console.WriteLine(result);
        Console.ReadKey(true);
    }

    private static JObject GetWebjobState(string webjobUrl, string userName, string userPWD)
    {
        HttpClient client = new HttpClient();
        string auth = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + ':' + userPWD));
        client.DefaultRequestHeaders.Add("authorization", auth);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        var data = client.GetStringAsync(webjobUrl).Result;
        var result = JsonConvert.DeserializeObject(data) as JObject;
        return result;
    }
}

您可以使用类似的函数来获取所有webjobs在自己的网站(使用端点<一个href=\"https://<website_name>.scm.azurewebsites.net/api/webjobs\">https://<website_name>.scm.azurewebsites.net/api/webjobs).你也可以看一下回到JObject验证webjob和其他财产的实际状态。

You can use a similar function to get all webjobs in your website (use endpoint https://<website_name>.scm.azurewebsites.net/api/webjobs). You may also look at the returned JObject to verify the actual state of the webjob and other properties.

这篇关于我怎样才能保持我的Azure WebJob运行没有&QUOT;始终在&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆