如何在 Azure Functions 的 http 函数中创建手动计时器触发器

How can I create a manual timer trigger in my http function of Azure Functions

我想在我的 http 函数中创建一个手动计时器触发器。 例如, 当我的函数收到 http 请求时,我想手动创建一个计时器触发器,以便在 30 分钟后触发另一个函数。

有人知道如何在 Azure Functions 中完成吗?

这是 Programmatically Schedule one-time execution of Azure function

的复制品

通过队列触发器完成您的实际工作,然后您可以使用延迟可见性对消息进行排队:

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);

正如我之前在评论中提到的,如果可能,您可以插入一条消息并指定 initialVisibilityDelay 当您的 http 函数收到请求时延迟 30 分钟,然后您可以使用队列触发函数来处理队列消息并执行一些任务。

如果您在 Azure 门户上创建 Azure 函数,您可以reference Microsoft.WindowsAzure.Storage并使用以下代码在您的 http 触发器函数中添加消息。

引用程序集和导入命名空间

#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;

添加消息并指定initialVisibilityDelay

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("{storage_connection_string}");

CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

CloudQueue queue = queueClient.GetQueueReference("mymes");

queue.CreateIfNotExists();

CloudQueueMessage message = new CloudQueueMessage("{message_body}");
queue.AddMessage(message, initialVisibilityDelay: TimeSpan.FromMinutes(30));

此外,您可以create a function triggered by Azure Queue storage处理您的队列消息。