Timer Event Source¶
FunctionGraph’s timer trigger (Timer Trigger) is a trigger type based on time scheduling that supports both Cron expression and fixed interval scheduling methods.
Through timer triggers, you can implement scheduled tasks, periodic data processing, scheduled backups, scheduled monitoring, and other functions.
Timer triggers are particularly suitable for tasks that need to be executed at fixed time intervals or specific time points, such as data cleanup, report generation, system monitoring, scheduled notifications, etc.
For details, see Using a Timer Trigger.
Timer example event¶
{
"version": "v1.0",
"time": "2023-06-01T08:30:00+08:00",
"trigger_type": "TIMER",
"trigger_name": "Timer_001",
"user_event": "{\"message\": \"timer triggered event\", \"topic\":\"test\"}"
}
Parameter description¶
Parameter |
Type |
Description |
|---|---|---|
version |
String |
Event version |
time |
String |
Time when an event occurs. |
trigger_type |
String |
Trigger type: TIMER |
trigger_name |
String |
Trigger name |
user_event |
String |
Additional information of the trigger |
Example¶
namespace src
{
#if NET6_0_OR_GREATER
using OpenTelekomCloud.Serverless.Function.Common;
#else
using HC.Serverless.Function.Common;
using OpenTelekomCloud.Serverless.Function.Common;
#endif
using OpenTelekomCloud.Serverless.Function.Events.Timer;
using System;
using System.IO;
using System.Text;
public class Program
{
/// <summary>
/// Main method - not used in FunctionGraph but needed for compilation
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
Console.WriteLine("This is a FunctionGraph C# runtime program");
}
public Stream Handler(Stream inputEvent, IFunctionContext context)
{
string payload = "";
var ms = new MemoryStream();
using (var sw = new StreamWriter(ms))
{
var logger = context.Logger;
logger.Logf("CSharp runtime test: Timer");
JsonSerializer serializer = new JsonSerializer();
TimerEvent anEvent = serializer.Deserialize<TimerEvent>(inputEvent);
if (anEvent != null)
{
payload = anEvent.ToString();
}
else
{
payload = "?";
}
sw.WriteLine(payload);
}
return new MemoryStream(ms.ToArray());
}
}
}