-1

I want to create a manual timer trigger in my http function. For example, When my function get a http request, I want to create a timer trigger manually so that trigger another function after 30 minutes.

Does anyone know how can i be done in Azure Functions?

Jan_V
  • 4,244
  • 1
  • 40
  • 64
Jie Wu
  • 27
  • 1
  • 2
    You do not need to create that timer trigger function, you can try to send a queue message and specify ``initialVisibilityDelay`` with 30 min delay when your http function get the request, and then you can use a queue trigger function to process the queue message. – Fei Han Sep 27 '17 at 08:58
  • Detailed information about [initialVisibilityDelay](https://learn.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.queue.cloudqueue.addmessage?redirectedfrom=MSDN&view=azurestorage-8.1.3#Microsoft_WindowsAzure_Storage_Queue_CloudQueue_AddMessage_Microsoft_WindowsAzure_Storage_Queue_CloudQueueMessage_System_Nullable_System_TimeSpan__System_Nullable_System_TimeSpan__Microsoft_WindowsAzure_Storage_Queue_QueueRequestOptions_Microsoft_WindowsAzure_Storage_OperationContext_) – Fei Han Sep 27 '17 at 08:59

2 Answers2

2

As I mentioned earlier in my comment, if possible, you can insert a message and specify initialVisibilityDelay with 30 min delay when your http function get the request, and then you can use a queue trigger function to process the queue message and do some tasks.

If you create Azure functions on Azure portal, you can reference Microsoft.WindowsAzure.Storage and use the following code to add message in your http trigger function.

Reference assemblies and import namespaces

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

Add message and specify 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));

Besides, you can create a function triggered by Azure Queue storage to process your queue messages.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
1

This is a dup of Programmatically Schedule one-time execution of Azure function

Have your real work done via a Queue Trigger, and then you can queue a message with deferred visibility:

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);
Mike S
  • 3,058
  • 1
  • 22
  • 12