No Emails Notification sent out when a new post is there

No Emails Notification sent out when a new post is there

by Bobby Jourdan -
Number of replies: 14
Hi there, I give up... smile I have read tons of info about similar issues and also have re-read the Cron explanation in Moodle docs. I just dont get it and I would appreciate a hand or at least a direction where I have to go to.

The forums on the Moodle I have (2.7) do not send email notifications out when there is a new post. I understand that this might be because of the cron job. I believe that the issue is that the email send out is not part of the scheduled tasks... When I go to Site Administration > Server > Scheduled tasks, I do not see a task that would relate to the email notifications. How do I add this task please?

Hereunder is what I get as a summary when I execute the php file (http://mysite.com/moodle/admin/cron.php) in a webbrowser.

Thank you so much in advance !


Execute scheduled task: Automated backups
... started 07:08:01. Current memory use 16.1MB.
Checking automated backup status...OK
Getting admin info
Checking courses
Skipping deleted courses...0 courses
Running required automated backups...
... started 07:08:01. Current memory use 24.9MB.

[here there are some automatic course back ups]

Automated backups complete.
... used 45 dbqueries
... used 0.14277315139771 seconds
Scheduled task complete: Automated backups
Execute scheduled task: Award badges
... started 07:08:01. Current memory use 24.9MB.
Started reviewing available badges.
Badges were issued 0 time(s).
Sending scheduled badge notifications.
... used 2 dbqueries
... used 0.019227027893066 seconds
Scheduled task complete: Award badges
Execute scheduled task: Delete stale temp files
... started 07:08:01. Current memory use 25.3MB.
... used 0 dbqueries
... used 0.12465596199036 seconds
Scheduled task complete: Delete stale temp files
Execute scheduled task: Background processing for statistics
... started 07:08:09. Current memory use 25.3MB.
... used 0 dbqueries
... used 1.7166137695312E-5 seconds
Scheduled task complete: Background processing for statistics
Cron script completed correctly
Cron completed at 07:08:09. Memory used 25.3MB.
Execution took 10.540893 seconds
Average of ratings: Useful (1)
In reply to Bobby Jourdan

Re: No Emails Notification sent out when a new post is there

by Alex MacNeil -

Hi Bobby,

I am looking for an answer to exactly the same problem. I will watch with interest and let you know in the unlikely event that I find something!


Regards

In reply to Bobby Jourdan

Re: No Emails Notification sent out when a new post is there

by Jesus Marquez -

Hi Bobby!

You could fix this. Im tired and i can not find solution.

Thank

In reply to Bobby Jourdan

Re: No Emails Notification sent out when a new post is there

by Chandrashekar Ramanathan -

Hello there,

I would like to say "me too" for this problem of forum e-mails not going out all of a sudden for the last three days (even though other mails like forgot passwords are sent out properly). I get a similar output to what Bobby has posted when I invoke cron.php. If you look closely, what you will notice that the scheduled task for sending out forum posting is not even listed there.

So after further digging around, I figured out that we could manually run the forum scheduled task as follows if you have access to the server command line interface:

sudo php /var/www/moodle/admin/tool/task/cli/schedule_task.php  --execute=\\mod_forum\\task\\cron_task

When I run the above command, the program terminates with the following error:

Cannot obtain task lock

Now I have no idea how to proceed further. What is causing the task to fail to obtain that lock? Is there anything I can do (like clearing some cache) to release all locks??

Any help is highly appreciated please.

Best regards

Chandrashekar



In reply to Chandrashekar Ramanathan

Re: No Emails Notification sent out when a new post is there

by Chandrashekar Ramanathan -

Dear all,

I was wondering if there is any advise for reviving the forum scheduled task that stopped working all of a sudden. Quite frustrating when all other scheduled tasks run properly through cron except this one.

Is there anyway to just delete and recreate the forum scheduled task alone? Will rebooting the server help? What else should I be looking for?

Any help is highly appreciated because we rely heavily on forum activities.

Many thanks in advance,

Chandrashekar


In reply to Chandrashekar Ramanathan

Re: No Emails Notification sent out when a new post is there

by Chandrashekar Ramanathan -
Hello all,

I thought I will post an update with a small progress we have made. Since we were getting some task locking error when trying to invoke the forum scheduled task, we took a chance and simply rebooted the server. And voila, the forum task began appearing in the list of tasks invoked by cron.php
Execute scheduled task: Forum mailings and maintenance jobs
But this good news has still not translated into receiving forum e-mail. Still trying to figure that part out.

Regards
Chandrashekar
In reply to Chandrashekar Ramanathan

Re: No Emails Notification sent out when a new post is there

by Erin Milanese -

I'll chime in and say we're having the same issue on Moodle 2.8. 

Cron appears fine... have checked various settings based on other threads related to this issue and still no luck. argh!! 

In reply to Erin Milanese

Re: No Emails Notification sent out when a new post is there

by Erin Milanese -

For anyone still working on a solution to this issue - we finally identified one for our situation. 

The issue was actually personal notification settings, which seems like something we should have caught earlier, but didn't. 

We changed the settings to force email subscriptions to forums and that's fixed our problem. 

Site Admin > plug ins > logging > default message outputs , and change Forum to forced. 

Hope that helps someone!

- Erin

In reply to Erin Milanese

Re: No Emails Notification sent out when a new post is there

by David Zeitler -

Guess I'll jump in here. I'm running 2.7.3+ (Build: 20141224) and have these same symptoms. Emails from the forums stopped several days ago. The cron job and all other tasks are running fine based both on the cron logs and the server scheduled tasks page. Executing the forum crontask from the cli gets the same 'Cannot obtain task lock' others have seen. I don't have access to the web server, but have asked the sysadmin to reboot it. No reply yet. Setting the forum post messages to 'forced' in site admin didn't help. I was hoping this would bypass the crontask, but evidently not. In the mean time I've also dug about in the code a bit and the locking mechanism is not immediately clear, but obviously the mechanism isn't foolproof. There needs to be a means of overriding a stuck lock like this.

In reply to David Zeitler

Re: No Emails Notification sent out when a new post is there

by David Zeitler -

Thought I'd update folks. This problem disappeared after rebooting our server. Simple solution, but the problem really should not exist.

In reply to David Zeitler

Re: No Emails Notification sent out when a new post is there

by Chandrashekar Ramanathan -

I just wanted to flag that we seem to be running into "cannot obtain task lock" problem more frequently now and rebooting seems to get things moving again. Obviously there must a better way to deal with the problem and even to prevent it from happening in the first place.

Any inputs highly appreciated.

Thanks

Chandrashekar


In reply to Chandrashekar Ramanathan

Re: No Emails Notification sent out when a new post is there

by Chandrashekar Ramanathan -

I thought I will post an update on our "cannot obtain task lock" travails for everyone's benefit.

There has been a significant increase in the number of users, number of forums and number of forum posts in our environment. We use Office365 to send out the forum postings as e-mails and use "forced subscription" across all our forums. When I run the forum task manually, I notice that the system takes about 3-5 seconds to send out each post (I just looked at the scrolling screen when I run the task from command line).

The forum task is configured by default to run every 30 minutes. I suspect that we run into "cannot obtain task lock" issue when the task started at time T is still running when the one for T+30 kicks in. So we intend increasing the forum task duration to a larger value and see if solves the problem.

Any other suggestions welcome please.

Thanks

Chandrashekar


In reply to Erin Milanese

Re: No Emails Notification sent out when a new post is there

by Stephen Lowe -

This is like saying, "Have you got petrol in your tank?" so forgive me if you do! You have got an email server configured? 

Just look in here before you go further...

Site administration > Plugins > Message outputs > Email

In reply to Chandrashekar Ramanathan

Re: No Emails Notification sent out when a new post is there

by Ryan-Neal Mes -

Hi there,

This kind of relates to the general post, but I am replying to this specific post since it relates most to my problem.

I thought I would write a bit about my findings for the next person coming to this thread since I had a rough time figuring out what the actual problem was causing "Cannot obtain task lock". So here it goes.

Moodle runs crons in the background which are usually long running processes that can potentially overlap each other. Meaning before it's finished running something is can start running that same thing again ... e.g. backups. This obviously is not ideal and moodle has come to the table with a great solution - locks. It took a while to figure out and understand these locks, but moodle has a couple of different ways of handling locks. The default uses the files system. It has a set of files in moodledirectory/locks that are used to keep track of what is locked or what isn't locked. If you are interested in seeing how things fit together check out lib/classes/lock directory. All the files are in there. Another important file to check out is admin/tool/task/cli/schedule_task.php 

Anyway the main gist and problem of the file locking mechanism seems like using flock (php function to lock files found in lib/classes/lock/file_lock_factory.php function get_lock) is that it's brittle. I'm not sure why they would use something that's not great. If you look at the documentation they say "On windows, a second attempt to get a lock will block indefinitely instead of timing out.". I am not using windows, but I think the same thing is happening for us. The great thing is you can swap out locking mechanisms. You can use the database or in memory storage like memcache (I think this requires a plugin).

All you need to do to swap over to the database is update your config with

$CFG->lock_factory = "\\core\\lock\\db_record_lock_factory";

This obviously comes with the cost of hitting your database, but for us we would much rather know that it's working.

If you want to check what's locked you can check the table mdl_lock_db

After changing over to this everything started working.


Some references

https://docs.moodle.org/28/en/Administration_via_command_line#Running_cron_via_command_line

https://tracker.moodle.org/browse/MDL-11309

https://tracker.moodle.org/browse/MDL-25500


Some tips

If you ever find yourself in this situation, dive into the code and drop some echo statements or var_dumps to find out what is actually happening. Disclaimer - don't do this on production and make sure you delete any traces once your are done. 


Average of ratings: Useful (1)