Programmatically Schedule one-time execution of Azure function

后端 未结 4 525
礼貌的吻别
礼貌的吻别 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.

    0 讨论(0)
  • 2021-01-13 09:16

    The other answers are all valid options, but there are some others as well.

    For Logic Apps you can build this behavior into the app as described in the Scheduler migration guide. The solution described there is to create a logic app with a http trigger, and pass the desired execution time to that trigger (in post data or query parameters). The 'Delay Until' block can then be used to postpone the execution of the following steps to the time passed to the trigger. You'd have to change the logic app to support this, but depending on the use case that may not be an issue.

    For Azure functions a similar pattern could be achieved using Durable Functions which has support for Timers.

    0 讨论(0)
  • 2021-01-13 09:18

    One option is to create Azure Service Bus Messages in your App using the ScheduledEnqueueTimeUtc property. This will create the message in the queue, but will only be consumable at that time.

    Then a Logic App could be listening to that Service Bus Queue and doing the further processing, e.g. SendGrid, Twilio, etc...

    HTH

    0 讨论(0)
  • 2021-01-13 09:20

    You can use Azure Automation to schedule tasks programmatically using REST API. Learn about it here.

    You can use Azure Event Grid also. Based on this article you can “Extend existing workflows by triggering a Logic App once there is a new record in your database".

    Hope this helps.

    0 讨论(0)
提交回复
热议问题