CRM-16387 - Locks - Use LockManager. Cleanup names.
authorTim Otten <totten@civicrm.org>
Thu, 14 May 2015 00:54:51 +0000 (17:54 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 15 Jun 2015 17:34:04 +0000 (10:34 -0700)
CRM/Contact/BAO/GroupContactCache.php
CRM/Core/BAO/Cache.php
CRM/Core/Lock.php
CRM/Mailing/BAO/Mailing.php
CRM/Mailing/BAO/MailingJob.php
api/v3/Job.php
bin/ContributionProcessor.php
bin/deprecated/CiviReportMail.php
bin/deprecated/EmailProcessor.php

index 7267bd80e243feb5f485ca65e00173461fe0f06b..a1cf6d594e87940aa3b09b1a5c1415bf47c97f06 100644 (file)
@@ -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.
index dab56685d80cc2f0dcce0361c038b8208643c2e0..acfca02dc7d0b41b81d0c62ee3bc700b0988f43e 100644 (file)
@@ -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();
     }
index f0be5f18fffe50f3eb0935ba4efa6a7ac963310b..7dcfaa5c0c6e9aa8d581538bcfb2e584e453753b 100644 (file)
@@ -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;
index df4329f44f8302585cc0119fb4454bf4b1a6ebe3..516512a89af3a3a9ee11e161635302b8b04c2429 100644 (file)
@@ -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;
index 3317790cd2b364bbc68d5fd140cfe352e0240202..c42e8c680000cc92e0f61ba512e9aaec8a05d6a0 100644 (file)
@@ -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;
       }
index 5a0e45c738d4cf9f51436bf09495553bd2a35fcf..c6a27618e4b6d9f17fde80bf6aebc03271f4612d 100644 (file)
@@ -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');
   }
index 45bd0b52292526d39e87f593249b0451be262309..57abe9cb453e98d34da76ca480299392f447b44b 100644 (file)
@@ -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();
index dc2edeb01fd22ff78a367bcd6794bd62dc1c80e2..27470ce7e8d819f376d347e4940ec6917af88b4e 100644 (file)
@@ -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
index 1cca94fa926aad4b8df8a2e068d054d11f283fd5..745fd7ba972f18b8539888673f7cccc8cd234397 100644 (file)
@@ -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');