MDL-49740 Lock: Fixed task lock release bugs

This commit is contained in:
Brendan Heywood 2015-04-02 17:41:48 +11:00
parent 1d3fd63f97
commit 894f36abf9
3 changed files with 24 additions and 20 deletions

View file

@ -109,7 +109,7 @@ if ($execute = $options['execute']) {
$predbqueries = $DB->perf_get_queries(); $predbqueries = $DB->perf_get_queries();
$pretime = microtime(true); $pretime = microtime(true);
try {
mtrace("Scheduled task: " . $task->get_name()); mtrace("Scheduled task: " . $task->get_name());
// NOTE: it would be tricky to move this code to \core\task\manager class, // NOTE: it would be tricky to move this code to \core\task\manager class,
// because we want to do detailed error reporting. // because we want to do detailed error reporting.
@ -119,15 +119,19 @@ if ($execute = $options['execute']) {
exit(129); exit(129);
} }
if (!$lock = $cronlockfactory->get_lock('\\' . get_class($task), 10)) { if (!$lock = $cronlockfactory->get_lock('\\' . get_class($task), 10)) {
$cronlock->release();
mtrace('Cannot obtain task lock'); mtrace('Cannot obtain task lock');
exit(130); exit(130);
} }
$task->set_lock($lock); $task->set_lock($lock);
if (!$task->is_blocking()) { if (!$task->is_blocking()) {
$cronlock->release(); $cronlock->release();
} else { } else {
$task->set_cron_lock($cronlock); $task->set_cron_lock($cronlock);
} }
try {
get_mailer('buffer'); get_mailer('buffer');
$task->execute(); $task->execute();
if (isset($predbqueries)) { if (isset($predbqueries)) {

View file

@ -216,7 +216,7 @@ class db_record_lock_factory implements lock_factory {
// Called from the shutdown handler. Must release all open locks. // Called from the shutdown handler. Must release all open locks.
foreach ($this->openlocks as $key => $unused) { foreach ($this->openlocks as $key => $unused) {
$lock = new lock($key, $this); $lock = new lock($key, $this);
$this->release_lock($lock); $lock->release();
} }
} }
} }

View file

@ -236,7 +236,7 @@ class postgres_lock_factory implements lock_factory {
// Called from the shutdown handler. Must release all open locks. // Called from the shutdown handler. Must release all open locks.
foreach ($this->openlocks as $key => $unused) { foreach ($this->openlocks as $key => $unused) {
$lock = new lock($key, $this); $lock = new lock($key, $this);
$this->release_lock($lock); $lock->release();
} }
} }