Removed useless transaction managers
authorThierry Florac <tflorac@ulthar.net>
Sat, 14 Mar 2015 13:28:39 +0100
changeset 5 0fe262326e0e
parent 4 03b9d3744d75
child 6 4a1bc9eb89ad
Removed useless transaction managers
src/pyams_scheduler/process.py
--- a/src/pyams_scheduler/process.py	Thu Mar 12 09:06:19 2015 +0100
+++ b/src/pyams_scheduler/process.py	Sat Mar 14 13:28:39 2015 +0100
@@ -66,41 +66,36 @@
         logger.debug("Loading ZEO connection...")
         with self._get_connection() as root:
             logger.debug("Loaded ZODB root {0!r}".format(root))
-            tm = None
             try:
-                try:
-                    application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
-                                                                          PYAMS_APPLICATION_DEFAULT_NAME)
-                    application = root.get(application_name)
-                    logger.debug("Loaded application {0!r}".format(application))
-                    sm = application.getSiteManager()
-                    scheduler_util = sm.get(SCHEDULER_NAME)
-                    logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
-                    scheduler = self.process.scheduler
-                    logger.debug("Removing job '{0}'".format(job_id))
-                    job = scheduler.get_job(job_id)
-                    if job is not None:
-                        logger.debug("Loaded job {0!r} ({0.id!r})".format(job))
-                        scheduler.remove_job(job.id)
-                    logger.debug("Loading scheduler task '{0}'".format(settings.get('task_name').lower()))
-                    task = scheduler_util.get(settings.get('task_name').lower())
-                    logger.debug("Loaded scheduler task {0!r}".format(task))
-                    if task is not None:
-                        trigger = task.get_trigger(self.process.registry)
-                        logger.debug("Getting task trigger {0!r}".format(trigger))
-                        zeo_connection = sm.getUtility(IZEOConnection, name=scheduler_util.zeo_connection)
-                        logger.debug("Adding new job to scheduler {0!r}".format(scheduler))
-                        scheduler.add_job(task, trigger,
-                                          id=str(task.internal_id),
-                                          name=task.name,
-                                          kwargs={'zeo_settings': zeo_connection.get_settings(),
-                                                  'registry': self.process.registry})
-                        logger.debug("Added job")
-                except:
-                    logger.exception("An exception occurred:")
-            finally:
-                if tm is not None:
-                    tm.abort()
+                application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
+                                                                      PYAMS_APPLICATION_DEFAULT_NAME)
+                application = root.get(application_name)
+                logger.debug("Loaded application {0!r}".format(application))
+                sm = application.getSiteManager()
+                scheduler_util = sm.get(SCHEDULER_NAME)
+                logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
+                scheduler = self.process.scheduler
+                logger.debug("Removing job '{0}'".format(job_id))
+                job = scheduler.get_job(job_id)
+                if job is not None:
+                    logger.debug("Loaded job {0!r} ({0.id!r})".format(job))
+                    scheduler.remove_job(job.id)
+                logger.debug("Loading scheduler task '{0}'".format(settings.get('task_name').lower()))
+                task = scheduler_util.get(settings.get('task_name').lower())
+                logger.debug("Loaded scheduler task {0!r}".format(task))
+                if task is not None:
+                    trigger = task.get_trigger(self.process.registry)
+                    logger.debug("Getting task trigger {0!r}".format(trigger))
+                    zeo_connection = sm.getUtility(IZEOConnection, name=scheduler_util.zeo_connection)
+                    logger.debug("Adding new job to scheduler {0!r}".format(scheduler))
+                    scheduler.add_job(task, trigger,
+                                      id=str(task.internal_id),
+                                      name=task.name,
+                                      kwargs={'zeo_settings': zeo_connection.get_settings(),
+                                              'registry': self.process.registry})
+                    logger.debug("Added job")
+            except:
+                logger.exception("An exception occurred:")
 
 
 class TaskRemoverThread(BaseTaskThread):
@@ -116,28 +111,23 @@
         logger.debug("Loading ZEO connection...")
         with self._get_connection() as root:
             logger.debug("Loaded ZODB root {0!r}".format(root))
-            tm = None
             try:
-                try:
-                    application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
-                                                                          PYAMS_APPLICATION_DEFAULT_NAME)
-                    application = root.get(application_name)
-                    logger.debug("Loaded application {0!r}".format(application))
-                    sm = application.getSiteManager()
-                    scheduler_util = sm.get(SCHEDULER_NAME)
-                    logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
-                    scheduler = self.process.scheduler
-                    logger.debug("Removing job '{0}'".format(job_id))
-                    job = scheduler.get_job(job_id)
-                    if job is not None:
-                        logger.debug("Loaded job {0!r} ({0.id!r})".format(job))
-                        scheduler.remove_job(job.id)
-                    logger.debug("Removed job")
-                except:
-                    logger.exception("An exception occurred:")
-            finally:
-                if tm is not None:
-                    tm.abort()
+                application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
+                                                                      PYAMS_APPLICATION_DEFAULT_NAME)
+                application = root.get(application_name)
+                logger.debug("Loaded application {0!r}".format(application))
+                sm = application.getSiteManager()
+                scheduler_util = sm.get(SCHEDULER_NAME)
+                logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
+                scheduler = self.process.scheduler
+                logger.debug("Removing job '{0}'".format(job_id))
+                job = scheduler.get_job(job_id)
+                if job is not None:
+                    logger.debug("Loaded job {0!r} ({0.id!r})".format(job))
+                    scheduler.remove_job(job.id)
+                logger.debug("Removed job")
+            except:
+                logger.exception("An exception occurred:")
 
 
 class TaskRunnerThread(BaseTaskThread):
@@ -152,38 +142,33 @@
         logger.debug("Loading ZEO connection...")
         with self._get_connection() as root:
             logger.debug("Loaded ZODB root {0!r}".format(root))
-            tm = None
             try:
-                try:
-                    application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
-                                                                          PYAMS_APPLICATION_DEFAULT_NAME)
-                    application = root.get(application_name)
-                    logger.debug("Loaded application {0!r}".format(application))
-                    sm = application.getSiteManager()
-                    scheduler_util = sm.get(SCHEDULER_NAME)
-                    logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
-                    scheduler = self.process.scheduler
-                    logger.debug("Loading scheduler task '{0}'".format(settings.get('task_name').lower()))
-                    task = scheduler_util.get(settings.get('task_name').lower())
-                    logger.debug("Loaded scheduler task {0!r}".format(task))
-                    if task is not None:
-                        trigger = ImmediateTaskTrigger()
-                        logger.debug("Getting task trigger {0!r}".format(trigger))
-                        zeo_connection = sm.getUtility(IZEOConnection, name=scheduler_util.zeo_connection)
-                        logger.debug("Adding new job to scheduler {0!r}".format(scheduler))
-                        scheduler.add_job(task, trigger,
-                                          id='{0.internal_id}::{1}'.format(task,
-                                                                           datetime.utcnow().isoformat()),
-                                          name=task.name,
-                                          kwargs={'zeo_settings': zeo_connection.get_settings(),
-                                                  'registry': self.process.registry,
-                                                  'run_immediate': True})
-                        logger.debug("Added job")
-                except:
-                    logger.exception("An exception occurred:")
-            finally:
-                if tm is not None:
-                    tm.abort()
+                application_name = self.process.registry.settings.get(PYAMS_APPLICATION_SETTINGS_KEY,
+                                                                      PYAMS_APPLICATION_DEFAULT_NAME)
+                application = root.get(application_name)
+                logger.debug("Loaded application {0!r}".format(application))
+                sm = application.getSiteManager()
+                scheduler_util = sm.get(SCHEDULER_NAME)
+                logger.debug("Loaded scheduler utility {0!r}".format(scheduler_util))
+                scheduler = self.process.scheduler
+                logger.debug("Loading scheduler task '{0}'".format(settings.get('task_name').lower()))
+                task = scheduler_util.get(settings.get('task_name').lower())
+                logger.debug("Loaded scheduler task {0!r}".format(task))
+                if task is not None:
+                    trigger = ImmediateTaskTrigger()
+                    logger.debug("Getting task trigger {0!r}".format(trigger))
+                    zeo_connection = sm.getUtility(IZEOConnection, name=scheduler_util.zeo_connection)
+                    logger.debug("Adding new job to scheduler {0!r}".format(scheduler))
+                    scheduler.add_job(task, trigger,
+                                      id='{0.internal_id}::{1}'.format(task,
+                                                                       datetime.utcnow().isoformat()),
+                                      name=task.name,
+                                      kwargs={'zeo_settings': zeo_connection.get_settings(),
+                                              'registry': self.process.registry,
+                                              'run_immediate': True})
+                    logger.debug("Added job")
+            except:
+                logger.exception("An exception occurred:")
 
 
 class SchedulerHandler(object):