Thursday, January 22, 2009

Moodle Pilot: Lesson Learned

Problem Description:

As part of the Moodle pilot process, we were batch loading Fresno State 26,000 user accounts from the converted Peoplesoft-Blackboard data extracts. The user accounts were created properly, however, due to the large amount of user records and the Moodle a-synchronized emailing mechanism generated a huge amount of repeated email notifications.

Findings:

Moodle is using a CRON job to send out email notifications. The following code selects all the records into a record set and loop through it to send out emails. Upon successfully emailing the user, each record then gets deleted from the database. However, with the huge amount of records, it may cause RACE Condition that the next cron job picks up the records already being queued for process.


//
// generate new password emails for users
//
mtrace('checking for create_password');
if (count_records('user_preferences', 'name', 'create_password', 'value', '1')) {
mtrace('creating passwords for new users');
$newusers = get_records_sql("SELECT u.id as id, u.email, u.firstname,
u.lastname, u.username,
p.id as prefid
FROM {$CFG->prefix}user u
JOIN {$CFG->prefix}user_preferences p ON u.id=p.userid
WHERE p.name='create_password' AND p.value=1 AND u.email !='' ");

foreach ($newusers as $newuserid => $newuser) {
$newuser->emailstop = 0; // send email regardless
// email user
if (setnew_password_and_mail($newuser)) {
// remove user pref
delete_records('user_preferences', 'id', $newuser->prefid);
} else {
trigger_error("Could not create and mail new user password!");
}
}
}

Solutions:
- Increasing the CRON job interval; or,
- Dividing the batch load to groups.

p.s. Increasing interval of CRON jobs may also delay the email delivery of new items posted in forums as well.

p.s. about the Moodle cron job:
http://docs.moodle.org/en/RedHat_Linux_installation#Set_up_the_cron_job, or
http://docs.moodle.org/en/Cron

No comments:

Post a Comment