Adhoc scheduled task?

Adhoc scheduled task?

per Daniel Neis Araujo -
Nombre de respostes: 4
Imatge Core developers Imatge Particularly helpful Moodlers Imatge Plugin developers Imatge Translators

Hello,


is there a way to schedule a task to run once in future?

What I am trying to achieve with this is the following:

* Let's say the user has to do something at least N minutes, so when the user starts to do something, I would like to schedule a task to now + N minutes that will check if it's done and take the necessary actions (of course it will take care of user's logouts and session timeouts and so, but there is no reason to test if it's done before the minimum amount of time and I think this approach is better than call a query each minute (even if it is only one query for all users)).

In classic unix cron I could set all the "time variables", that includes the year (moodle does not have year on it's syntax), and it would be executed only once in the expected date/time. But then that task would be there forever and would accumulate with others of the same kind and it's not really a good side effect.

Does anyone have any ideas?


Kind regards,

Daniel

Mitjana de qualificacions: -
En resposta a Daniel Neis Araujo

Re: Adhoc scheduled task?

per Brendan Anderson -

When the user does the thing, you could kick off another process to monitor his or her progress. I have had success with Gearman for similar stuff and it has a nice PHP client. The Gearman job could just sleep for N minutes and then check back with Moodle through it's web services to see if the user has completed the task. Or better, the job could be a Moodle CLI script, so it can communicate with Moodle directly.

Honestly, it's a lot to set up though. The more conventional approach is probably better, especially if many people are engaged in this workflow. If you run a query for users who have begun, but not completed, a task every single time cron runs, it is a waste only if no users are returned.

En resposta a Brendan Anderson

Re: Adhoc scheduled task?

per Daniel Neis Araujo -
Imatge Core developers Imatge Particularly helpful Moodlers Imatge Plugin developers Imatge Translators

Hello, Brendan


this Gearman seems to be a nice tool, but really also seems to much work.

When you say "The Gearman job could just sleep for N minutes and then check", well, that is not really that elegant too, and could be done with Moodle's ad-hoc tasks that are non-blockable by default and run in background.


Kind regards,

Daniel


En resposta a Daniel Neis Araujo

Re: Adhoc scheduled task?

per Michael Aherne -
Imatge Core developers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge Plugin developers

I don't think that's possible at the moment. It would be a useful feature, though, so it might be worth raising in the Moodle Tracker.

On the face of it, it looks as if it would be a simple change to the queue_adhoc_task() method, to avoid overwriting a "next run time" value if one is supplied. It's possible it was implemented the way it is deliberately to prevent some other problem, though, so it's maybe not that simple.