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:
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:
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.
LICENSE and README.md
Refer to 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 plugin:
Section | key | Value | Description | Example |
---|---|---|---|---|
[settings] | runtime | Any Python or NodeJS valid version | This is the environment in which the plugin will run |
|
[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. |
|
[settings.cron] | run_on_deploy* | true or false | Determines if the plugin shall be executed immediately upon creation |
|
With that in mind, a typical manifest.toml file for a Private Cron plugin looks like:
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
andfunction.py
If your plugin is using NodeJS as runtime, the scripts' names should be
control.js
andfunction.js
The language selected for the control
and function
scripts must match with the value of theruntime
key in the manifest.toml file
Last updated