Ejemplo n.º 1
0
 /**
  * Will release a lock with the given name, 
  *  if it has been acquired before
  */
 public function release()
 {
     if ($this->counter > 1) {
         // this is a lock that we acquired multiple times:
         //  simply decrease counter
         $this->counter -= 1;
         //CRM_Core_Error::debug_log_message('released ' . getmypid() . "[{$this->counter}]");
     } elseif ($this->counter == 1) {
         // simply release the lock
         $this->counter = 0;
         $this->lock->release();
         self::$_acquired_lock = NULL;
         //CRM_Core_Error::debug_log_message('released ' . getmypid());
     } else {
         // lock has already been released!
         CRM_Core_Error::debug_log_message("de.systopia.donrec: This process cannot realease lock '{$name}', it has already been released before.");
         throw new Exception("This process cannot realease lock '{$name}', it has already been released before.");
     }
 }
Ejemplo n.º 2
0
 /**
  * Get a batching lock
  *
  * the lock is needed so that only one relevant process can access the
  * payment/statment data structures at a time
  *
  * @return lock object. check if it ->isAcquired() before use
  */
 public static function getLock($type, $id)
 {
     if ($type == '') {
         // for the 'next' lock, we calculate the lock timeout as follows
         $max_lock_timeout = ini_get('max_execution_time');
         if (empty($max_lock_timeout)) {
             $max_lock_timeout = 30 * 60;
             // 30 minutes
         }
         // calculate based on chunk size (max 1min/item)
         $calculation_time = CRM_Donrec_Logic_Settings::getChunkSize() * 60;
         $timeout = min($calculation_time, $max_lock_timeout);
     } else {
         // default timeout for other locks
         $timeout = 600.0;
         // 10mins, TODO: do we need a setting here?
     }
     //CRM_Core_Error::debug_log_message("de.systopia.donrec.$type".'-'.$id." timeout $timeout created.");
     return CRM_Utils_DonrecSafeLock::acquireLock("de.systopia.donrec.{$type}" . '-' . $id, $timeout);
 }