Cron

Definition

A Private Cron plugin is a user-defined logic that gets executed periodically, according to a defined frequency by the user.

Required files

As stated before any plugin type, and, particularly a Private Cron plugin, is composed by the file structure shown below:

├── src
│   ├── control     
│   ├── function
│   ├── view.xml
├── LICENSE
├── README.md 
├── manifest.toml 

control

This is a script, written either in Python or NodeJS. This can be thought as a "setup" script since it will run only once at the moment of creating the plugin.

function

This is a script, written either in Python or NodeJS. It will be executed based on the set frequency.

view.xml

This file provides the developer with the capability to build and display a form, where the users can input the plugin's required parameters.

The contents of this form are displayed when the Cron plugin is being created.

For instance, consider a plugin requiring information from the user such as:

  • A device's position

  • Plugin execution period

  • Ubidots token

Said form might look like this:

The developer can create a form displaying those fields by using the view.xml as shown below:

<form name="formName">

    <group name="locacionGroup">
        <group name="location">
            <label name="labelLocation">Click on the map to specify a location</label>
            <map name="map" />
        </group>
    </group>

    <group name="unitsGroup">
        <group name="unitsSelect">
            <label name="labelUnits">Units format</label>
            <select
              name="units"
              placeholder="Units format"
              value="metric"
              type="single"
            >
                    <option value="metric">Metric</option>
                    <option value="imperial">Imperial</option>
            </select>
        </group>
    </group>

    <group name="freq">        
        <group name="freqInfo">
            <frequency label="Run every {field} minutes"/>
        </group>
        <label name="labelUnits" help="Please note data is updated every 10 to 20 minutes"></label>
    </group>

    <group name="ubidotsInformation">
        <group name="fieldToken">
            <label name="labelToken">Ubidots Token</label>
            <token name="token" placeholder="Select Token"/>
        </group>
    </group>
</form>

All of these parameters in the form are accessible to the function and control scripts on each of its executions within the _parameters key in the incoming JSON object.

For detailed information about the supported form elements, please head to the view.xml section in the Plugins development page.

view.xml

LICENSE and README.md

Refer to Private Plugins page to get more information:

Private Plugins

Manifest.toml

Aside from the manifest components common to all plugin types, the following are specific to Cron type plugin:

SectionkeyValueDescriptionExample

[settings]

runtime

Any Python or NodeJS valid version

This is the environment in which the plugin will run

runtime = "python:3.7"

[settings.cron]

interval

Any integer number, T, in the range: 1 < T < y. This value is in minutes.

Default frequency with which the plugin will be executed.

interval = 1

[settings.cron]

run_on_deploy*

true or false

Determines if the plugin shall be executed immediately upon creation

run_on_deploy = false

With that in mind, a typical manifest.toml file for a Private Cron plugin looks like:

manifest_version = 2.0
 
[settings] 
version = "1.0.56" 
runtime = "nodejs:10" | "python:3.7"
plugin_type = "cron" 
license_name = "MIT license" 

[settings.cron] 
interval = 1 
run_on_deploy = false

[pricing]
price = 0 

Manifest's file keys marked with a * means that its not mandatory and can be omitted/not set.

Naming convention

You ought to retain the names of all files and directories mentioned in the "required files" section, as the plugins engine specifically searches for these files and their extensions.

For instance:

  • If your plugin is using Python as runtime, the scripts' names should be control.py and function.py

  • If your plugin is using NodeJS as runtime, the scripts' names should be control.js and function.js

The language selected for the control and functionscripts must match with the value of theruntime key in the manifest.toml file

Last updated