Changeset 136ed9a in indico
- Timestamp:
- 03/15/11 11:13:44 (2 years ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- 33e0d7
- Parents:
- ee3e75
- git-author:
- Pedro Ferreira <jose.pedro.ferreira@…> (03/14/11 18:25:09)
- git-committer:
- Pedro Ferreira <jose.pedro.ferreira@…> (03/15/11 11:13:44)
- Location:
- indico
- Files:
-
- 5 edited
-
MaKaC/authentication/LDAPAuthentication.py (modified) (1 diff)
-
MaKaC/common/db.py (modified) (1 diff)
-
MaKaC/plugins/RoomBooking/default/dalManager.py (modified) (6 diffs)
-
modules/scheduler/slave.py (modified) (4 diffs)
-
modules/scheduler/tasks.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/authentication/LDAPAuthentication.py
r7d30d5 r136ed9a 380 380 av = {} 381 381 av["email"] = [ret['mail']] 382 av["name"] = ret ['givenName']383 av["surName"] = ret ['sn']382 av["name"] = ret.get('givenName', '') 383 av["surName"] = ret.get('sn', '') 384 384 385 385 if 'o' in ret: -
indico/MaKaC/common/db.py
r755a70 r136ed9a 197 197 self._storage.tpc_finish(trans) 198 198 199 def transaction(self): 200 """ 201 Calls the ZODB context manager (`with`) 202 """ 203 return self._db.transaction() 204 199 205 # ZODB version check 200 206 try: -
indico/MaKaC/plugins/RoomBooking/default/dalManager.py
r336214 r136ed9a 18 18 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 19 19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 20 21 import threading 22 from contextlib import contextmanager 20 23 21 24 from MaKaC.common import Configuration … … 30 33 from ZODB.DB import DB 31 34 import transaction 35 36 37 @contextmanager 38 def dummyContextManager(): 39 yield 40 41 42 class DummyConnection(): 43 """ 44 Used so that we can use context managers for database connections 45 without producing failures when RB is not active. 46 Of course tis is not the ideal solution, but it's the best possible 47 without changing the whole RB DB code. 48 """ 49 def transaction(self): 50 return dummyContextManager() 32 51 33 52 … … 110 129 self.db.pack(days=days) 111 130 131 def transaction(self): 132 """ 133 Calls the ZODB context manager for the connection 134 """ 135 return self.db.transaction() 136 112 137 113 138 class DALManager(DALManagerBase): 114 139 """ ZODB specific implementation. """ 115 140 116 _instance = None141 _instances = {} 117 142 118 143 @staticmethod … … 126 151 127 152 @staticmethod 128 def getInstance(): 129 if not DALManager._instance: 153 def getInstance(create=True): 154 tid = threading._get_ident() 155 instance = DALManager._instances.get(tid) 156 157 if not instance and create: 130 158 minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() 131 DALManager._instance = DBConnection(minfo) 132 if not DALManager._instance: 133 raise "cannot open DB backend" 134 return DALManager._instance 159 instance = DBConnection(minfo) 160 DALManager._instances[tid] = instance 161 return instance 135 162 136 163 @staticmethod … … 139 166 Returns true if the current DALManager is connected 140 167 """ 141 return DALManager._instance.isConnected() 168 if DALManager.getInstance(create=False): 169 return DALManager.getInstance().isConnected() 170 else: 171 return False 142 172 143 173 @staticmethod 144 174 def getRoot(name=""): 145 return DALManager. _instance.getRoot(name)175 return DALManager.getInstance().getRoot(name) 146 176 147 177 @staticmethod … … 151 181 @staticmethod 152 182 def disconnect(): 153 DALManager. _instance.disconnect()183 DALManager.getInstance().disconnect() 154 184 155 185 @staticmethod 156 186 def commit(): 157 DALManager. _instance.commit()187 DALManager.getInstance().commit() 158 188 159 189 @staticmethod 160 190 def rollback(): 161 DALManager. _instance.rollback()191 DALManager.getInstance().rollback() 162 192 163 193 @staticmethod 164 194 def sync(): 165 DALManager. _instance.sync()195 DALManager.getInstance().sync() 166 196 167 197 @staticmethod 168 198 def pack(days=1): 169 DALManager._instance.pack() 199 DALManager.getInstance().pack() 200 201 @staticmethod 202 def dummyConnection(): 203 return DummyConnection() -
indico/modules/scheduler/slave.py
r336214 r136ed9a 29 29 import threading 30 30 31 from ZODB.POSException import ConflictError 32 31 33 class _Worker(object): 32 34 … … 47 49 self._dbi.startRequest() 48 50 49 info = HelperMaKaCInfo.getMaKaCInfoInstance()50 schedMod = SchedulerModule.getDBInstance()51 self._rbEnabled = info.getRoomBookingModuleActive()51 with self._dbi.transaction(): 52 schedMod = SchedulerModule.getDBInstance() 53 self._task = schedMod.getTaskById(self._taskId) 52 54 53 if self._rbEnabled:54 self._rb dbi = DBConnection(info)55 info = HelperMaKaCInfo.getMaKaCInfoInstance() 56 self._rbEnabled = info.getRoomBookingModuleActive() 55 57 56 self._task = schedMod.getTaskById(self._taskId) 58 if self._rbEnabled: 59 self._rbdbi = DALManager.getInstance() 60 self._rbdbi.connect() 61 else: 62 self._rbdbi = DALManager.dummyConnection() 57 63 58 64 # open a logging channel 59 65 self._task.plugLogger(self._logger) 60 61 self._dbi.endRequest()62 66 63 67 def run(self): … … 71 75 i = 0 72 76 73 self._dbi.startRequest()74 77 # RoomBooking forces us to connect to its own DB if needed 75 78 # Maybe we should add some extension point here that lets plugins 76 79 # define their own actions on DB connect/disconnect/commit/abort 77 80 78 if self._rbEnabled:79 self._rbdbi.connect()80 81 81 # potentially conflict-prone (!) 82 self._task.prepare() 83 self._dbi.commit() 84 if self._rbEnabled: 85 self._rbdbi.commit() 82 with self._dbi.transaction(): 83 with self._rbdbi.transaction(): 84 self._task.prepare() 86 85 87 86 while i < self._config.task_max_tries: 87 try: 88 with self._dbi.transaction(): 89 with self._rbdbi.transaction(): 88 90 89 self._logger.info('Task cycle %d' % i) 91 self._logger.info('Task cycle %d' % i) 92 i = i + 1 93 try: 94 self._task.start() 95 break 90 96 91 i = i + 192 try:93 self._task.start()97 except Exception, e: 98 nextRunIn = i * 10 # secs 99 self._logger.exception('Error message') 94 100 95 except Exception, e:96 nextRunIn = i * 10 # secs101 raise 102 except: 97 103 self._logger.warning("Task %s failed with exception '%s'. " % 98 (self._task.id, e)) 99 100 self._logger.exception('Error message') 104 (self._task.id, e)) 101 105 102 106 if i < self._config.task_max_tries: 103 self._logger.warning("Retrying for the %dth time in %d secs.." % 107 self._logger.warning("Retrying for the %dth time in %d secs.." % \ 104 108 (i + 1, nextRunIn)) 105 109 … … 109 113 base.TimeSource.get().sleep(nextRunIn) 110 114 111 # abort transaction and synchronize112 self._dbi.sync()113 if self._rbEnabled:114 self._rbdbi.abort()115 else:116 break117 118 115 self._logger.info('Ended on: %s' % self._task.endedOn) 119 116 120 if self._task.endedOn: # task successfully finished 121 self._setResult(True) 117 # task successfully finished 118 if self._task.endedOn: 119 with self._dbi.transaction(): 120 self._setResult(True) 122 121 if i > 1: 123 122 self._logger.warning("Task %s failed %d times before " 124 123 "finishing correctly" % (self._task.id, i - 1)) 125 124 else: 126 self._setResult(False) 125 with self._dbi.transaction(): 126 self._setResult(False) 127 127 self._logger.error("Task %s failed too many (%d) times. " 128 128 "Aborting its execution.." % (self._task.id, i)) 129 129 130 if self._rbEnabled: 131 self._rbdbi.commit() 132 self._rbdbi.disconnect() 133 self._dbi.endRequest() 134 self._logger.info("exiting") 130 self._logger.info("exiting") 135 131 136 132 -
indico/modules/scheduler/tasks.py
r4ec29c r136ed9a 19 19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 20 20 21 import copy, logging, time,os21 import copy, logging, os 22 22 from dateutil import rrule 23 23 24 from datetime import timedelta25 from pytz import timezone26 from pytz import common_timezones27 24 import zope.interface 28 25 … … 31 28 from MaKaC.i18n import _ 32 29 from MaKaC.common import Config 33 from MaKaC.common.info import HelperMaKaCInfo34 from MaKaC.common.Counter import Counter35 30 # end required 36 31 … … 372 367 addrs = [smtplib.quoteaddr(x) for x in self.toAddr] 373 368 ccaddrs = [smtplib.quoteaddr(x) for x in self.ccAddr] 369 370 if len(addrs) + len(ccaddrs) == 0: 371 self._v_logger.warning("Attention: mail contains no recipients!") 372 else: 373 self._v_logger.info("Sending mail To: %s, CC: %s" % (addrs, ccaddrs)) 374 374 375 375 for user in self.toUser: … … 567 567 if check: 568 568 from MaKaC.conference import ConferenceHolder 569 if not ConferenceHolder().hasKey(self.conf.getId()) or \ 570 self.conf.getStartDate() <= self._getCurrentDateTime(): 569 if not ConferenceHolder().hasKey(self.conf.getId()): 570 self._logger.warning("Conference %s no longer exists! " 571 "Deleting alarm." % self.conf.getId()) 572 self.conf.removeAlarm(self) 573 elif self.conf.getStartDate() <= self._getCurrentDateTime(): 574 self._logger.warning("Conference %s already started. " 575 "Deleting alarm." % self.conf.getId()) 571 576 self.conf.removeAlarm(self) 572 577 return True
Note: See TracChangeset
for help on using the changeset viewer.
