To set up a periodically running task in social engine one we must create tasks. Periodically running tasks are usually accomplished by setting up a cron job. But in social engine we piggy back in the task scheduler which can be set up to trigger in a number of ways. Cron being one of them.
The first step is to add a row for our task in the table engine4_core_tasks. The only fields you need to are:
- title — this is the text that appears under “Name” in the task scheduler page
- module — which module the task belongs. Disabling the module also disables the task
- plugin — the class that defines the action to run. Named <ModuleName>_Plugin_Task_<TaskName>
- timeout — the number of seconds between task execution. Setting this to 60 means your task will execute every minute.
You may add this query in the settings/my.sql or settings my.upgrade-x.x.x-x.x.x.sql in case of upgrades.
Next we need to define the plugin class. This is located in application/modules/<ModuleName>/Plugin/Task/<TaskName>. We just need to extends Core_Plugin_Task_Abstract and define the public method execute. Within this method we write the statements the we need to run when the task is executed.
There are a lot of useful information in the tasks log. I suggest you monitor this log as during testing and debugging. In addition you may add debugging information in this log with $this->getLog()->debug(‘<debug info>’).
Originally published in https://social-engine-tutorials.blogsplot.com.