Programmatically Schedule one-time execution of Azure function

后端 未结 4 570
礼貌的吻别
礼貌的吻别 2021-01-13 08:39

I have looked through documentation for WebJobs, Functions and Logic Apps in Azure but I cannot find a way to schedule a one-time execution of a process through code. My use

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-13 09:13

    You could use Azure Queue trigger with deferred visibility. This will keep the message invisible for a specified timeout. This conveniently acts as a timer.

    CloudQueue queueOutput; // same queue as trigger listens on 
    var strjson = JsonConvert.SerializeObject(message); // message is your payload
    var cloudMsg = new CloudQueueMessage(strjson);
    
    var delay = TimeSpan.FromHours(1); 
    queueOutput.AddMessage(cloudMsg, initialVisibilityDelay: delay);
    

    See https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.storage.queue.cloudqueue.addmessage?view=azure-dotnet for more details on this overload of AddMessage.

提交回复
热议问题