簡體   English   中英

Azure函數中實例id獲取主機鎖租約的原因是什么?

[英]What is the reason for host lock lease acquired by instance id in Azure function?

我正在運行一個具有 Azure 功能的項目,但它沒有運行我的 azure 功能。 我已經設置了斷點,它也沒有達到斷點。 此外,輸出不清楚,因此我可以調試我的代碼。 有什么方法可以調試代碼以找到問題的根本原因嗎?

輸出:

[3/20/2018 9:39:31 AM] 讀取主機配置文件 'C:\\Users\\myname\\Source\\MyProject\\aspnet-core\\src\\Nec.MyProject.Processors\\bin\\Debug\\netstandard2.0\\host .json' [3/20/2018 9:39:31 AM] 主機配置文件讀取:[3/20/2018 9:39:31 AM] { [3/20/2018 9:39:31 AM] "queues ": { [3/20/2018 9:39:31 AM] "maxPollingInterval": 1000, [3/20/2018 9:39:31 AM]
"visibilityTimeout": "00:00:00", [3/20/2018 9:39:31 AM]
"batchSize": 1, [3/20/2018 9:39:31 AM] "maxDequeueCount": 5 [3/20/2018 9:39:31 AM] } [3/20/2018 9:39:31 AM] ] } [3/20/2018 9:39:48 AM] 生成 15 個作業函數 [3/20/2018 9:39:48 AM] 啟動主機 (HostId=windowsmyname-655615619, Version=2.0.11415.0, ProcessId=6320, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=) [3/20/2018 9:39:49 AM] 發現以下函數:[3/20/2018 9:39:49 AM] MyCompany.MyProject.Processors.BackOfficeFilesGeneratorJobs.RunTestGeneratorAsync [3/20/2018 9:39:49 AM] [3/20/2018 9:39:49 AM] 工作主機開始監聽http://localhost:7071/ 按CTRL -C 退出... [3/20/2018 9:39:50 AM] 實例 ID '0000000000000000000000000C78D3496' 獲取主機鎖租約。

天藍色功能:

[FunctionName("GenerateTestOfficeMasterDataFiles")]
public static async Task RunTestGeneratorAsync(
    [QueueTrigger("%MasterDataFiles:Supplier:QueueName%", Connection = "ConnectionStrings:BlobStorageAccount")] BackOfficeFileGeneratorMessage<string> message,
    ExecutionContext context,
    TraceWriter log)

注意:當它是BackOfficeFileGeneratorMessage而不是BackOfficeFileGeneratorMessage<string>時,它工作正常。

更新:

public class BackOfficeFileGeneratorMessage<TEntityKey>
{
    public BackOfficeFileGeneratorMessage()
    {
        Items = new MasterDataFileOperationItem <TEntityKey>[0];
    }
    public bool UseStaging { get; set; }
    public string StoreNo { get; set; }
    public bool RefreshAll { get; set; }
    public IEnumerable<MasterDataFileOperationItem <TEntityKey>> Items { get; set; }
}

Functions 運行時使用特定於您的函數應用程序的唯一 ID 獲取附加到函數應用程序的存儲帳戶的租用。 這是一個內部實現細節。

只要隊列觸發器數據與 POCO 匹配,反序列化為泛型類型就應該可以工作。 例如,這里是泛型類型

public class GenericInput<T>
{
    public T OrderId { get; set; }

    public T CustomerName { get; set; }
}

和功能

 public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<string> message, TextWriter log)
    {
        log.WriteLine(message);
    }

示例隊列數據

{
  "OrderId" : 1,
  "CustomerName" : "john" 
}

如果無法將隊列數據序列化為預期的 GenericType,則會出現序列化錯誤。 例如,以下函數在嘗試處理錯誤隊列輸入時會失敗:函數:

public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<int> message, TextWriter log)
    {
        log.WriteLine(message);
    }

輸入錯誤:

{
 "OrderId" : 1,
 "CustomerName" : "cannot covert string to number" 
}

只需將下一個 key:value 添加到hosts.json

"singleton": {
    "listenerLockPeriod": "00:00:15" 
  }

如果您在 blob 上上傳文件並對其運行觸發器,則該文件將僅被讀取一次。 如果您需要為同一個文件再次運行該函數,這是不可能的。 您可以從 blob 中刪除文件,然后使用 UI(它將用作新觸發器)將其再次放在那里,或者更改您機器上函數的路徑並將文件原樣保留在 blob 上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM