# 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.&#x20;

## 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:

<figure><img src="https://884329393-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MhzNRg0B4ECiNXc093G%2Fuploads%2FEpk9KVPQhAHOPU3j0dfc%2FGroup%2033.png?alt=media&#x26;token=9ec83b31-84dd-4b4d-ad3a-1ddf863da4fd" alt=""><figcaption></figcaption></figure>

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

```xml
<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.

{% hint style="info" %}
For detailed information about the supported elements in the view\.xml file, head to its dedicated section in the "[Plugins development](https://dev.ubidots.com/plugins/plugins-development/view.xml)" page.
{% endhint %}

## LICENSE and README.md

Refer to the "Private Plugins" page to get more information:

{% content-ref url="" %}
[](https://dev.ubidots.com/plugins/private-plugins)
{% endcontent-ref %}

## Manifest.toml

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

<table data-full-width="true"><thead><tr><th align="center">Section</th><th align="center">Key</th><th align="center">Value</th><th align="center">Description</th><th align="center">Example</th></tr></thead><tbody><tr><td align="center">[settings]</td><td align="center">runtime</td><td align="center">Any Python or NodeJS valid version.</td><td align="center">This is the environment in which the plugin will run.</td><td align="center"><code>runtime = "python:3.7"</code></td></tr><tr><td align="center">[settings.cron]</td><td align="center">interval</td><td align="center">Any integer number, T,  in the range:<br> 1 &#x3C; T &#x3C; y. This value is in minutes.</td><td align="center">Default frequency at which the plugin will be executed.</td><td align="center"><code>interval = 1</code></td></tr><tr><td align="center">[settings.cron]</td><td align="center">run_on_deploy*</td><td align="center"><em>true</em> or <em>false</em></td><td align="center">Determines if the plugin will be executed immediately upon creation</td><td align="center"><code>run_on_deploy = false</code></td></tr></tbody></table>

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 
```

{% hint style="info" %}
Manifest's file keys marked with a \* mean that they're not mandatory and can be omitted/not set.
{% endhint %}

## 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.&#x20;

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`

{% hint style="info" %}
The language selected for the `control` and `function`scripts must match with the value of th&#x65;*`runtime`* key in the manifest.toml file
{% endhint %}
