Skip to content

Timer Trigger

Overview

Triggers determine how the App Functions Pipeline begins execution which can be found by the [Trigger] section in the configuration.yaml file, see Application Service Triggers for more detailed information. Edge Xpert provides a proprietary TimerTrigger configuration to execute the function pipelines periodically. The common use cases of the TimeTrigger ususally start with XpertHTTPExport_GET functions pipeline which will be demonstrated in the example below.

Sample Configuration

The following code defines the configuration of TimerTrigger:

[Trigger]
Type="timer"
  [Trigger.Timer]
  Interval = "10s"

The following table describes the configuration parameters used to define TimerTrigger:

Configuration Mandatory Description
Type Yes Must specify timer
Interval Yes Must specify time intervals

Example

If Edge Xpert CLI utility is installed, a sample configuration can be found in /usr/share/edgexpert/examples/app-configurable/timer-trigger/configuration.toml for TimerTrigger.This article will take you through steps by implementing XpertHTTPExport_GET and PrintDataToLog function pipeline to demonstrate the usage of TimerTrigger.

  1. Copy and save the sample configuration file as a separate file (for example, timer-trigger.toml) to your working directory.

  2. The default function pipelines in this example are XpertHTTPExport_GET and PrintDataToLog. You can use XpertHTTPExport_GET function to issue an HTTP GET request and PrintDataToLog will print out the response body of XpertHTTPExport_GET.

    [Writable.Pipeline]
    ExecutionOrder = "XpertHTTPExport_GET,PrintDataToLog"
    
  3. Change the log level to DEBUG to observe the detailed information in the later step

    [Writable]
      LogLevel = "DEBUG"
    
  4. Specify the Interval based on the scenarios, this example indicates the functions pipelines should be triggered every 10 seconds.

    [Trigger]
    Type="timer"
      [Trigger.Timer]
      Interval = "10s"
    
  5. Once the configuration is ready, you can launch the application service using command below:

    • If your Edge Xpert is running under secure mode, enter the following command, replacing the path with your configuration file:

      edgexpert up --secret app-service --path=<path your confgiuration file>
      

    • If your Edge Xpert is running under insecure mode, enter the following command, replacing the path with your configuration file:

      edgexpert up app-service --path=<path your confgiuration file>
      

  6. Monitor the log from the running app service. If everything works fine, you should observe similar log as shown below:

    level=DEBUG ts=2023-08-16T10:09:34.994377302+08:00 app=app-configuration source=timer.go:66 msg="Timer trigger ticked..."
    level=DEBUG ts=2023-08-16T10:09:34.994494383+08:00 app=app-configuration source=timer.go:91 msg="prepare to trigger pipelines from timer trigger..."
    level=DEBUG ts=2023-08-16T10:09:34.994573494+08:00 app=app-configuration source=runtime.go:220 msg="Pipeline 'default-pipeline' processing message 2 Transforms"
    level=DEBUG ts=2023-08-16T10:09:34.99468618+08:00 app=app-configuration source=http.go:184 msg="HTTP Exporting in pipeline 'default-pipeline'"
    level=DEBUG ts=2023-08-16T10:09:34.994728514+08:00 app=app-configuration source=http.go:209 msg="sending HTTP GET request to https://postman-echo.com/get in pipeline 'default-pipeline'"
    level=DEBUG ts=2023-08-16T10:09:35.781772832+08:00 app=app-configuration source=http.go:267 msg="Sent 0 bytes of data in pipeline 'default-pipeline'. Response status is 200 OK"
    level=INFO ts=2023-08-16T10:09:35.782199287+08:00 app=app-configuration source=printdatatolog.go:17 msg="Data: {\n  \"args\": {},\n  \"headers\": {\n    \"x-forwarded-proto\": \"https\",\n    \"x-forwarded-port\": \"443\",\n    \"host\": \"postman-echo.com\",\n    \"x-amzn-trace-id\": \"Root=1-64dc2fe0-65669dde2b2ca7d65990a3c5\",\n    \"user-agent\": \"Go-http-client/1.1\",\n    \"content-type\": \"application/json\",\n    \"accept-encoding\": \"gzip\"\n  },\n  \"url\": \"https://postman-echo.com/get\"\n}"
    level=DEBUG ts=2023-08-16T10:09:35.782238246+08:00 app=app-configuration source=timer.go:110 msg="Successfully execute pipelines from timer trigger (CorrelationID:40130c5c-c3b5-4edc-a33b-5ff16938aae3)"