General developer forum

Execute code at specific time

Picture of jeroen van bennekum
Execute code at specific time


I need to run some code at a specific datetime set by a user. I have an adhock class and try to set its next runtime 30 seconds in the future (for now to test) but it doesn't seem to be ran and also not queued based on:


Here is my adhock class:


class event_deadline_warning extends \core\task\adhoc_task {
public function execute() {
error_log('custom ABOUT TO SEND NOTIF IN ADHOC TASK');
send_notification(44, 'SUBJECT', 'TEXT', 'TEXT');
Which has a error log to see if it is executed and some (test) code to be ran. (This part is never ran)

Here is my code to trigger all this:

$deadline = new event_deadline_warning();
$run_at = time() + 30;//Set
error_log('custom NOW = ' . $run_at);


error_log('custom QUEUED: ' . $deadline->get_next_run_time());
Which does output the error logs so I am sure this is actually ran.

Is there something I am doing wrong? How can I schedule a task at a specific time to run some code only once?

Average of ratings: -
Picture of Darko Miletić
Re: Execute code at specific time
Core developersParticularly helpful Moodlers
Scheduled task execution depends on the cron being executed regularly.

Setup Moodle cron to be executed frequently.

El lun., 24 sept. 2018 8:04 a. m., jeroen van bennekum (via <
Average of ratings: -