Timer Event Source¶
You can schedule a timer to invoke your code based on a fixed rate of minutes, hours, or days or a cron expression. For details, see Using a Timer Trigger.
Timer example event¶
{
"version": "v1.0",
"time": "2018-06-01T08:30:00+08:00",
"trigger_type": "TIMER",
"trigger_name": "Timer_001",
"user_event": "User Event"
}
Parameter description¶
Parameter |
Type |
Example Value |
Description |
|---|---|---|---|
version |
String |
V1.0 |
Event version |
time |
String |
2018-06-01T08:30:00+08:00 |
Time when an event occurs. |
trigger_type |
String |
TIMER |
Trigger type |
trigger_name |
String |
Timer_001 |
Trigger name |
user_event |
String |
User Event |
Additional information of the trigger |
Example¶
package main
import (
"encoding/json"
"fmt"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/events/timer"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/go-api/context"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/pkg/runtime"
)
// Example for Timer handler
func TimerTest(payload []byte, ctx context.RuntimeContext) (interface{}, error) {
var timerEvent timer.TimerTriggerEvent
err := json.Unmarshal(payload, &timerEvent)
if err != nil {
fmt.Println("Unmarshal failed")
return "invalid data", err
}
return timerEvent.String(), nil
}
func main() {
runtime.Register(TimerTest)
}