Template Functions

Template functions are used to inject values into pipeline configurations.

NOTE: A value starting with { is parsed as an object by YAML, so you will need to quote values.

Environment Variables

The env template function injects the content of an environment variable into a config. To inject an object, store JSON in the environment variable.

Syntax

{{ env "<variable-name>" }}

Example

The following example injects both the NATS authentication and the database connection parameters into the Optimus Mine configuration.

Environment variables:

NATS_AUTH="user:password"
MYSQL_CONNECTION='{"host":"db.example.com:3306","database":"my_database","user":"root","password":"P4$$W0rd"}'

Optimus config:

tasks:
  - engine: nats:subscribe
    url: nats://{{ env "NATS_AUTH" }}@nats.example.com:4222
    subject: my_subject
  - engine: mysql:export
    connection: '{{ env "MYSQL_CONNECTION" }}'
    table: my_table

Resulting config:

tasks:
  - engine: nats:subscribe
    url: nats://user:password@nats.example.com:4222
    subject: my_subject
  - engine: mysql:export
    connection:
      host: db.example.com:3306
      database: my_database
      user: root
      password: P4$$W0rd
    table: my_table

User Directory

The userDir template function returns the current user’s home directory.

Syntax

{{ userDir }}

Example

The following example will store the resulting file on the user’s desktop.

tasks:
  - <data-source>
  - engine: file:export
    path: '{{ userDir }}/Desktop/my_data.csv'
    encoder: csv

Date/Time

The date template function returns the current date and time in the format defined by an Excel-style date format.

Syntax

{{ date "<date-format>" }}

Date Format

Code Description
M month (1)
MM month (01)
MMM month (Jan)
MMMM month (January)
D day (2)
DD day (02)
DDD day (Mon)
DDDD day (Monday)
YY year (06)
YYYY year (2006)
hh hours (15)
mm minutes (04)
ss seconds (05)
AM/PM hours

To display time in AM/PM hours, append pm to your time format e.g.

Code Description
hpm hours (03PM)
h:mmpm hours:minutes (03:04PM)
h:mm:sspm hours:minutes:seconds (03:04:05PM)
Time zones

To specify a time zone format, append ‘ZZZZ’, ‘ZZZ’ or ‘ZZ’ to your time format e.g.

Code Description
hh:mm:ss ZZZZ (16:05:06 +0100)
hh:mm:ss ZZZ (16:05:06 CET)
hh:mm:ss ZZ (16:05:06 +01:00)

Example

The following example stores data in a file containing the current date and time in the name.

Optimus config:

tasks:
  - <data-source>
  - engine: file:export
    path: my_data_{{ date "YYYY-MM-DD_hh-mm-ss" }}.csv
    encoder: csv

Resulting filename:

my_data_2023-06-24_15-05-06.csv