From: Tim Otten Date: Thu, 14 May 2015 00:54:51 +0000 (-0700) Subject: CRM-16387 - Locks - Use LockManager. Cleanup names. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=33c5988bf60454453949f9d883e78fa0c4678066;p=civicrm-core.git CRM-16387 - Locks - Use LockManager. Cleanup names. --- diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 7267bd80e2..a1cf6d594e 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -434,8 +434,7 @@ WHERE id = %1 } // grab a lock so other processes dont compete and do the same query - $lockName = "civicrm.group.{$groupID}"; - $lock = new CRM_Core_Lock($lockName); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.core.group.{$groupID}"); if (!$lock->isAcquired()) { // this can cause inconsistent results since we dont know if the other process // will fill up the cache before our calling routine needs it. diff --git a/CRM/Core/BAO/Cache.php b/CRM/Core/BAO/Cache.php index dab56685d8..acfca02dc7 100644 --- a/CRM/Core/BAO/Cache.php +++ b/CRM/Core/BAO/Cache.php @@ -151,8 +151,7 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { // get a lock so that multiple ajax requests on the same page // dont trample on each other // CRM-11234 - $lockName = "civicrm.cache.{$group}_{$path}._{$componentID}"; - $lock = new CRM_Core_Lock($lockName); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("cache.{$group}_{$path}._{$componentID}"); if (!$lock->isAcquired()) { CRM_Core_Error::fatal(); } diff --git a/CRM/Core/Lock.php b/CRM/Core/Lock.php index f0be5f18ff..7dcfaa5c0c 100644 --- a/CRM/Core/Lock.php +++ b/CRM/Core/Lock.php @@ -130,7 +130,7 @@ class CRM_Core_Lock implements \Civi\Core\Lock\LockInterface { if (self::$jobLog && CRM_Core_DAO::singleValueQuery("SELECT IS_USED_LOCK( '" . self::$jobLog . "')")) { return $this->hackyHandleBrokenCode(self::$jobLog); } - if (stristr($name, 'civimail.job.')) { + if (stristr($name, 'data.mailing.job.')) { self::$jobLog = $this->_name; } $this->_timeout = $timeout !== NULL ? $timeout : self::TIMEOUT; diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index df4329f44f..516512a89a 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -2911,12 +2911,8 @@ WHERE civicrm_mailing_job.id = %1 shuffle($lockArray); // check if we are using global locks - $serverWideLock = CRM_Core_BAO_Setting::getItem( - CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, - 'civimail_server_wide_lock' - ); foreach ($lockArray as $lockID) { - $cronLock = new CRM_Core_Lock("civimail.cronjob.{$lockID}", NULL, $serverWideLock); + $cronLock = Civi\Core\Container::singleton()->get('lockManager')->acquire("worker.mailing.send.{$lockID}"); if ($cronLock->isAcquired()) { $gotCronLock = TRUE; break; diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index 3317790cd2..c42e8c6800 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -136,9 +136,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob { while ($job->fetch()) { // still use job level lock for each child job - $lockName = "civimail.job.{$job->id}"; - - $lock = new CRM_Core_Lock($lockName); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}"); if (!$lock->isAcquired()) { continue; } @@ -344,9 +342,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob { // X Number of child jobs while ($job->fetch()) { // still use job level lock for each child job - $lockName = "civimail.job.{$job->id}"; - - $lock = new CRM_Core_Lock($lockName); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}"); if (!$lock->isAcquired()) { continue; } diff --git a/api/v3/Job.php b/api/v3/Job.php index 5a0e45c738..c6a27618e4 100644 --- a/api/v3/Job.php +++ b/api/v3/Job.php @@ -178,9 +178,9 @@ function civicrm_api3_job_send_reminder($params) { // in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0 // in the _spec function - but since that is a deprecated value it seems more contentious than this approach $params['rowCount'] = 0; - $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.ActionSchedule'); if (!$lock->isAcquired()) { - return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); + return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running'); } $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params); @@ -354,7 +354,7 @@ function civicrm_api3_job_process_sms($params) { * @return array */ function civicrm_api3_job_fetch_bounces($params) { - $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } @@ -377,7 +377,7 @@ function civicrm_api3_job_fetch_bounces($params) { * @return array */ function civicrm_api3_job_fetch_activities($params) { - $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } @@ -430,7 +430,7 @@ function civicrm_api3_job_process_participant($params) { * true if success, else false */ function civicrm_api3_job_process_membership($params) { - $lock = new CRM_Core_Lock('civimail.job.updateMembership'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.member.UpdateMembership'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running'); } @@ -616,7 +616,7 @@ function civicrm_api3_job_disable_expired_relationships($params) { * @throws \API_Exception */ function civicrm_api3_job_group_rebuild($params) { - $lock = new CRM_Core_Lock('civimail.job.groupRebuild'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.GroupRebuild'); if (!$lock->isAcquired()) { throw new API_Exception('Could not acquire lock, another EmailProcessor process is running'); } diff --git a/bin/ContributionProcessor.php b/bin/ContributionProcessor.php index 45bd0b5229..57abe9cb45 100644 --- a/bin/ContributionProcessor.php +++ b/bin/ContributionProcessor.php @@ -412,8 +412,7 @@ CRM_Utils_System::authenticateScript(TRUE); //log the execution of script CRM_Core_Error::debug_log_message('ContributionProcessor.php'); -require_once 'CRM/Core/Lock.php'; -$lock = new CRM_Core_Lock('CiviContributeProcessor'); +$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.contribute.CiviContributeProcessor'); if ($lock->isAcquired()) { // try to unset any time limits @@ -424,7 +423,7 @@ if ($lock->isAcquired()) { CiviContributeProcessor::process(); } else { - throw new Exception('Could not acquire lock, another CiviMailProcessor process is running'); + throw new Exception('Could not acquire lock, another CiviContributeProcessor process is running'); } $lock->release(); diff --git a/bin/deprecated/CiviReportMail.php b/bin/deprecated/CiviReportMail.php index dc2edeb01f..27470ce7e8 100644 --- a/bin/deprecated/CiviReportMail.php +++ b/bin/deprecated/CiviReportMail.php @@ -49,8 +49,7 @@ class CiviReportMail { } public function run() { - require_once 'CRM/Core/Lock.php'; - $lock = new CRM_Core_Lock('CiviReportMail'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.report.CiviReportMail'); if ($lock->isAcquired()) { // try to unset any time limits diff --git a/bin/deprecated/EmailProcessor.php b/bin/deprecated/EmailProcessor.php index 1cca94fa92..745fd7ba97 100644 --- a/bin/deprecated/EmailProcessor.php +++ b/bin/deprecated/EmailProcessor.php @@ -51,8 +51,7 @@ if (php_sapi_name() == "cli") { //if it doesn't die, it's authenticated //log the execution of script CRM_Core_Error::debug_log_message('EmailProcessor.php from the cli'); - require_once 'CRM/Core/Lock.php'; - $lock = new CRM_Core_Lock('EmailProcessor'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor'); if (!$lock->isAcquired()) { throw new Exception('Could not acquire lock, another EmailProcessor process is running'); @@ -83,8 +82,7 @@ else { //log the execution of script CRM_Core_Error::debug_log_message('EmailProcessor.php'); - require_once 'CRM/Core/Lock.php'; - $lock = new CRM_Core_Lock('EmailProcessor'); + $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor'); if (!$lock->isAcquired()) { throw new Exception('Could not acquire lock, another EmailProcessor process is running');