*/
class CRM_Core_Lock {
+ static $jobLog = FALSE;
+
// lets have a 3 second timeout for now
const TIMEOUT = 3;
if (defined('CIVICRM_LOCK_DEBUG')) {
CRM_Core_Error::debug_log_message('trying to construct lock for ' . $this->_name);
}
- static $jobLog = FALSE;
- if ($jobLog && CRM_Core_DAO::singleValueQuery("SELECT IS_USED_LOCK( '{$jobLog}')")) {
- return $this->hackyHandleBrokenCode($jobLog);
+ if (self::$jobLog && CRM_Core_DAO::singleValueQuery("SELECT IS_USED_LOCK( '" . self::$jobLog . "')")) {
+ return $this->hackyHandleBrokenCode(self::$jobLog);
}
if (stristr($name, 'civimail.job.')) {
- $jobLog = $this->_name;
+ self::$jobLog = $this->_name;
}
$this->_timeout = $timeout !== NULL ? $timeout : self::TIMEOUT;
* @return bool
*/
public function acquire() {
- if (defined('CIVICRM_LOCK_DEBUG')) {
- CRM_Core_Error::debug_log_message('acquire lock for ' . $this->_name);
- }
if (!$this->_hasLock) {
$query = "SELECT GET_LOCK( %1, %2 )";
$params = array(
);
$res = CRM_Core_DAO::singleValueQuery($query, $params);
if ($res) {
+ if (defined('CIVICRM_LOCK_DEBUG')) {
+ CRM_Core_Error::debug_log_message('acquire lock for ' . $this->_name);
+ }
$this->_hasLock = TRUE;
}
+ else {
+ if (defined('CIVICRM_LOCK_DEBUG')) {
+ CRM_Core_Error::debug_log_message('failed to acquire lock for ' . $this->_name);
+ }
+ }
}
return $this->_hasLock;
}
* @return null|string
*/
public function release() {
+ if (defined('CIVICRM_LOCK_DEBUG')) {
+ CRM_Core_Error::debug_log_message('release lock for ' . $this->_name . ' (' . ($this->_hasLock ? 'hasLock' : '!hasLock') . ')');
+ }
if ($this->_hasLock) {
$this->_hasLock = FALSE;
+ if (self::$jobLog == $this->_name) {
+ self::$jobLog = FALSE;
+ }
+
$query = "SELECT RELEASE_LOCK( %1 )";
$params = array(1 => array($this->_name, 'String'));
return CRM_Core_DAO::singleValueQuery($query, $params);
*/
public function hackyHandleBrokenCode($jobLog) {
if (stristr($this->_name, 'job')) {
- throw new CRM_Core_Exception('lock aquisition for ' . $this->_name . 'attempted when ' . $jobLog . 'is not released');
+ CRM_Core_Error::debug_log_message('lock acquisition for ' . $this->_name . ' attempted when ' . $jobLog . ' is not released');
+ throw new CRM_Core_Exception('lock acquisition for ' . $this->_name . ' attempted when ' . $jobLog . ' is not released');
}
if (defined('CIVICRM_LOCK_DEBUG')) {
CRM_Core_Error::debug_log_message('(CRM-12856) faking lock for ' . $this->_name);