So far, I've tried to mimick what mod_forum has done, I created a directory under class folder of my module for task classes: 'MYPLUGIN/classes/task'
With one class, 'send_to_ws', looking like this:
namespace mod_MYPLUGIN\task;
defined('MOODLE_INTERNAL') || die();
class send_to_ws extends \core\task\adhoc_task {
public function execute() {
$data = $this->get_custom_data();
$payload = json_encode(array("data"=> $data['info']));
$ch->post('http://127.0.0.1:8001/', array('info'=>$payload, 'file'=> $data['file']));
}
$sendfile = new mod_MYPLUGIN\task\send_to_ws();
$sendfile->set_custom_data(array(
'info' => $info,
'file' => $file,
));
\core\task\manager::queue_adhoc_task($sendfile);