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:
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:
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 elements in the view.xml file, head to its dedicated section in the "Plugins development" page.
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's file keys marked with a * mean that they're not mandatory and can be omitted/not set.
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
The language selected for the control
and function
scripts must match with the value of theruntime
key in the manifest.toml file
Last updated