Cron
Definition
A private cron plugin is a user-defined logic that gets executed periodically, according to a frequency defined by the user.
Required files
As stated before, any type of plugin (particularly a private cron plugin) is composed by this file structure:
βββ 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 of as a "set up" script, since it will only run 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 defined frequency.
view.xml
This file provides the developer the capability to build and display a form where 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:
The geographical location of a device.
The execution period of the plugin.
An Ubidots token.
Said form could 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.
LICENSE and README.md
Refer to the "Private Plugins" page to get more information:
Private PluginsManifest.toml
Aside from the manifest components common to all plugin types, the following are specific to cron-type plugins:
[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 at which the plugin will be executed.
interval = 1
[settings.cron]
run_on_deploy*
true or false
Determines if the plugin will 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 this:
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
Naming convention
You must employ 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
andfunction.py
If your plugin is using NodeJS as runtime, the scripts' names should be
control.js
andfunction.js
Last updated
Was this helpful?