Jump to content

Allow Modules To Add Cron Tasks


Blesta Addons

Recommended Posts

for a long time developing and discovering the new v3. i have found that allowing modules to add it own crontask like plugins , will be a great feature , as the addition for this is a easy task and not a heavy coding .

the modules is already handle the install() and uninstall() function inside module . and we can easly add and remode tasks . 

public function install() {
        Loader::loadModels($this, array("CronTasks"));

        $task = array(
            'key' => "my_task", // a string used to identify this cron task (see MyPluginPlugin::cron())
            'plugin_dir' => "my_plugin", // the plugin directory of this plugin
            'name' => "My Plugin Task", // the name of this cron task
            'description' => "This cron tasks does stuff", // the description of this task
            'type' => "time" // "time" = once per day at a defined time, "interval" = every few minutes or hours
        );

        $task_id = $this->CronTasks->add($task);
  
   if (!$task_id) {
    $cron_task = $this->CronTasks->getByKey($task['key'], $task['module_dir']);
    if ($cron_task)
     $task_id = $cron_task->id;
   }
  
   if ($task_id) {
    $task_vars = array('enabled' => $task['enabled']);
    if ($task['type'] == "interval")
     $task_vars['interval'] = $task['type_value'];
    else
     $task_vars['time'] = $task['type_value'];
   
    $this->CronTasks->addTaskRun($task_id, $task_vars);
   }
}

until here there are no probleme . 

 

the problem is comming from cron_task.php model , because it will not exucute any cron that is not belong to plugin enabled . if blesta staff can make some change the cron task structure , we can arrive to a working solution to achieve this task .

why modules need crontasks ?

some modules for registrar need tgis to check the transfer status .

some modules for hosting need this to sync data between blesta and server .

some modules can be mainly need to get data from api to parse some info into database , like statistiques and reports .

.......

also i know is possible to add a separate plugin for achieve this scenario , but i prefer maintain and code in one place , rather than make two reposity to achieve 1 more task .

Link to comment
Share on other sites

i see that maybe changing the cron_task.php is not a option for blesta team , so why not creating anew cron class just for modules , like cron_task_module.php is just dedicated to the module tasks .

then include it under the main model and in the automatisation section in admin side ?

is a good solution ?

Link to comment
Share on other sites

  • 2 years later...
32 minutes ago, Paul said:

Modules creating automation tasks? I could get on board with that. What are some use cases?

 

One is the Blesta module reaching out to say a server to fetch certain information via an API or other means, and Blesta being responsible for dealing with suspension of a service for exceeding a plan's resources on the assumption the there's no system on the other end to do it, or that you're extending existing functionality and it's most logical for Blesta to deal with this.

A cron is needed to reach out and grab said information for parsing.

Link to comment
Share on other sites

13 hours ago, Paul said:

Rather than allowing modules to register their own automation tasks, I wonder if it might make more sense to have a single automation task built into the system that can run tasks modules want to run periodically. I've created CORE-2435 to look at this.

This is what i have in my mind, i have made a shema for a plugin that i have called "cron hoster", the idea is a bit simple, the plugin has it own table that store the cron data like the core one, and it intern cron run every 5 min,  the only different is changing the plugin_dir by the module_dir , then the module can add cron via install() function , then in the module should have a function called cron(), this function will be executed by the plugin cron . 

this function will use it inf registrar modules to check transfers and domains expiration sync, export or import data to a remote server via API . this task will save us a lot of time and hard coding and this should be out with the new domain management and pricing .

Link to comment
Share on other sites

5 hours ago, Blesta Addons said:

This is what i have in my mind, i have made a shema for a plugin that i have called "cron hoster", the idea is a bit simple, the plugin has it own table that store the cron data like the core one, and it intern cron run every 5 min,  the only different is changing the plugin_dir by the module_dir , then the module can add cron via install() function , then in the module should have a function called cron(), this function will be executed by the plugin cron . 

this function will use it inf registrar modules to check transfers and domains expiration sync, export or import data to a remote server via API . this task will save us a lot of time and hard coding and this should be out with the new domain management and pricing .

I agree if it was possible to put required cron tasks directly in the module instead of making a filler plugin to do the cron only that would be easier for me to make my dedicated/colocation servers module.

Link to comment
Share on other sites

  • 6 months later...
13 hours ago, activa said:

Asked from 2015, requested and voted from users... maybe it will implemented next month ?

I would hope yes, because it would be easier for my colocation module planned as stated in my club to be finished to do the cron tasks inside the module to run cron tasks to retrieve snmp entries from a switch/router than to have to build a extra plugin just to do the cron tasks.

Link to comment
Share on other sites

On 05/02/2018 at 10:26 PM, Tyson said:

Allowing cron tasks, database access, etc. for modules makes them basically plugins at that point. We're re-evaluating the design of these extensions to be more accommodating.

Call them plugins, modules, addons or any other word not important for us. The important that they should do what we want . ( Dot Final)

Link to comment
Share on other sites

17 hours ago, activa said:

Call them plugins, modules, addons or any other word not important for us. The important that they should do what we want . ( Dot Final)

It's not about what they're called, but how they function in the grand design of the system so that they can do what you want. It's very important to get a good design down early or there will be problems down the road.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...