[v3.5] Task not running

[v3.5] Task not running

by Anze Pratnemer -
Number of replies: 5

No matter what I do, my task from local plugin is not running sad


Task is scheduled to run @ 15:55:



server time and crond status, showing that cron.php is scheduled to run



All other tasks are run (cron log shows activity every 1 minute), only my plugin turns into ASAP and stays like that:



What is wrong? How can I debug this?


Source code:

/local/studissync/db/tasks.php:

$tasks = array(                                                                                                                     

    array(                                                                                                                          

        'classname' => 'local_studissync\task\worker',                                                                            

        'blocking' => 0,                                                                                                            

        'minute' => '55',                                                                                                            

        'hour' => '15',                                                                                                              

        'day' => '*',                                                                                                               

        'dayofweek' => '*',                                                                                                         

        'month' => '*'                                                                                                              

    )

);


/local/studissync/classes/task/worker.php:

namespace local_studissync\task;

defined('MOODLE_INTERNAL') || die();


class worker extends \core\task\scheduled_task {

public function execute() {

mtrace("Starting sync with Studis!");


$sync = new \local_studissync\sync();

$result = $sync->do_sync();

(more code with mtrace commands inside)

}


/local/studissync/classes/sync.php:

namespace local_studissync;

defined('MOODLE_INTERNAL') || die();

class sync{

public function do_sync(){

(more code that returns array at the end)

}


Average of ratings: -
In reply to Anze Pratnemer

Re: [v3.5] Task not running

by Anze Pratnemer -

Is it really unsolvable problem or is there not enough information given for you guys to help me out?

In reply to Anze Pratnemer

Re: [v3.5] Task not running

by Ken Task -
Picture of Particularly helpful Moodlers

https://sos.sosoftexas.org/blog/index.php/2018/08/26/a-better-way-of-running-moodle-cron/

You have two cron jobs ... one for www-data - which is the recommended user under which to run cron on a Ubuntu boxen ... and one for root.   Why two?

As far as getting the task/cron to run for local_studissync that is an addon - not part of core ... one that you have developed, thus,  a 'better'? place to post and bump for you would be in the Developers forum, wouldn't it? smile

Old doc: https://docs.moodle.org/dev/Task_API

There is a section on 'Legacy Cron' that might be worth a read.

and another related: https://docs.moodle.org/dev/Scheduled_Tasks_Proposal

Am not a programmer/developer myself, BTW.

'spirit of sharing', Ken



In reply to Anze Pratnemer

Re: [v3.5] Task not running

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

I would say that your task is error'ing out in some way. Tasks do not write to the webserver error logs usually (because they are not run from the web server).

A quick way to see what is happening is to run the cron job from the web interface, ie

[my moodle server]/admin/cron.php

Then all the output will show on screen and with any luck you will see something like:

"local_studissync\task\worker class not found" 

which would be good information.

In reply to Justin Hunt

Re: [v3.5] Task not running

by Anze Pratnemer -
Hey,


thank you for your time. 


If I run this task via Run now.. link, task is run without any errors. I do have some mtrace commands in worker.php, maybe that sets him off?

If I run cron.php via web interface, i get this:

Server Time: Mon, 15 Oct 2018 09:46:26 +0200


Cron script completed correctly
Cron completed at 09:46:26. Memory used 3.4MB.
Execution took 0.043613 seconds
Where else could I check?


When I had >>cron.log after cron command in crond, there was shit ton of dumped data, but I didnt find any mentioning of my plugin. Could there be a problem in my code that task is not registered?


In reply to Anze Pratnemer

Re: [v3.5] Task not running

by Anze Pratnemer -

I went a step further and tried running via CLI with :

/usr/bin/php html/admin/tool/task/cli/schedule_task.php --execute=\\local_studissync\\task\\worker


which always returns: "Cannot obtain task lock". I tried setting blocking in task config to 1, but that didn't change anything. I added:

public function get_run_if_component_disabled(){

return true;

}

just in case my plugin is somehow disabled and I don't see that, but that didnt change outcome.


Then I stumbled upon this page: https://www.linuxito.com/gnu-linux/nivel-alto/686-resolver-cannot-obtain-task-lock-en-moodle which suggested that process may be stuck somehow. And it was true. I hade a cron.php task running from 2 weeks ago. Once killed, task is being run via cron on a scheduled time.


Now I have to check, why process gets stuck. I am getting data from 3rd party API, which sometimes gets unresponsive. Maybe I need to handle this exception.


So, this one is solved, writing followup just in case somebody else gets same problem.


Both of responsers, thank you for your time, you both contributed to finding solution..


Average of ratings: Useful (2)