在控制台中运行webjob但在Azure上引发异常:无法解析远程名称:' xxx.queue.core.windows.net'

时间:2016-09-09 02:44:31

标签: azure azure-storage azure-web-sites azure-storage-blobs

我的webjob从我的blob存储中删除文档。如果我将代码复制到控制台应用程序并运行它,它将运行完成而不会出现错误。如果我在visual studio中创建一个新的webjob(右键单击我的网站项目并选择Add - > New Azure Webjob项目),将代码复制到Functions.cs并部署,Azure在运行webjob时抛出异常:

import graphene
from django.db import connection
from collections import namedtuple


class OrderItemType(graphene.ObjectType):
    date = graphene.core.types.custom_scalars.DateTime()
    order_id = graphene.ID()
    uuid = graphene.String()

class QueryType(graphene.ObjectType):
    class Meta:
        type_name = 'Query' # This will be name in graphene 1.0

    order_items = graphene.List(OrderItemType)

    def resolve_order_items(root, args, info):
        return get_order_items()    


def get_db_rows(sql, args=None):
    cursor = connection.cursor()
    cursor.execute(sql, args)
    columns = [col[0] for col in cursor.description]
    RowType = namedtuple('Row', columns)
    data = [
        RowType(*row) # Edited by John suggestion fix
        for row in cursor.fetchall() ]

    cursor.close()
    return data

def get_order_items():
    return get_db_rows("""
        SELECT j.created_dt AS date, j.order_id, j.uuid
        FROM job AS j
        LIMIT 3;
    """)

我没有队列,所以这可能是错误来自哪里,但奇怪的是我不会尝试访问队列,我只访问我的blob存储。

不确定这是否有帮助,但我的webjobs Program.cs看起来像这样:

===============================================

[09/09/2016 01:51:44 > fc93a9: ERR ] Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The remote name could not be resolved: 'xxx.queue.core.windows.net' ---> System.Net.WebException: The remote name could not be resolved: 'xxx.queue.core.windows.net'
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    --- End of inner exception stack trace ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.EndExists(IAsyncResult asyncResult)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass1`1.<CreateCallback>b__0(IAsyncResult ar)
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Queues.Listeners.QueueListener.<ExecuteAsync>d__4.MoveNext()
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.TaskSeriesTimer.<RunAsync>d__d.MoveNext()
[09/09/2016 01:51:44 > fc93a9: ERR ] --- End of stack trace from previous location where exception was thrown ---
[09/09/2016 01:51:44 > fc93a9: ERR ]    at Microsoft.Azure.WebJobs.Host.Timers.BackgroundExceptionDispatcher.<>c__DisplayClass1.<Throw>b__0()
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
[09/09/2016 01:51:44 > fc93a9: ERR ]    at System.Threading.ThreadHelper.ThreadStart()
[09/09/2016 01:51:44 > fc93a9: SYS ERR ] Job failed due to exit code -532462766

=======================================================

这是作业中唯一使用存储的代码,其余的是获取列表的数据库内容等。

    static void Main()
    {
        JobHostConfiguration config = new JobHostConfiguration();
        config.Tracing.ConsoleLevel = TraceLevel.Verbose;

        config.UseTimers();

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

编辑:我还应该补充一点,这只是在更新后才开始:

  • Microsoft.Azure.WebJobs从1.1.1到1.1.2
  • Microsoft.Azure.WebJobs.Core 1.1.1至1.1.2
  • WindowsAzure.Storage从5.0.2到7.2.0和

还有一些代码更改和其他更新(如Newtonsoft.Json,Microsoft.WindowsAzure.ConfigurationManager,Microsoft.Web.WebJobs.Publish),但是我没有使用访问blob的方式更改代码。

更新 - 我的webjob在周末跑完了。它在22:23失败并出现与上述相同的错误,但在22:24重试时成功运行。但是今天再次以同样的错误再次失败。我将尝试删除@FleminAdambukulam所述的日志记录,但奇怪的是如何在没有任何代码更改的情况下运行,但之后再次失败......

1 个答案:

答案 0 :(得分:6)

问题是存储帐户属于仅支持Blob的特殊类型。即使您没有使用队列,WebJobs SDK也会在内部依赖它们。因此,要使用WebJobs SDK,您需要使用常规存储帐户。