def task_init(dbuser): """Prepare to run a task. :param dbuser: The database user to use for running the task. """ ensure_zcml() transaction.abort() store = IStore(Job) getUtility(IZStorm).remove(store) store.close() dbconfig.override(dbuser=dbuser, isolation_level='read_committed') install_feature_controller(make_script_feature_controller('celery'))
def run(self, use_web_security=False, isolation=None): """Actually run the script, executing zcml and initZopeless.""" if isolation is None: isolation = 'read_committed' self._init_zca(use_web_security=use_web_security) self._init_db(isolation=isolation) # XXX wgrant 2011-09-24 bug=29744: initZopeless used to do this. # Should be called directly by scripts that actually need it. set_immediate_mail_delivery(True) date_started = datetime.datetime.now(UTC) profiler = None if self.options.profile: profiler = Profile() original_feature_controller = get_relevant_feature_controller() install_feature_controller(make_script_feature_controller(self.name)) try: if profiler: profiler.runcall(self.main) else: self.main() except LaunchpadScriptFailure as e: self.logger.error(str(e)) sys.exit(e.exit_status) except SilentLaunchpadScriptFailure as e: sys.exit(e.exit_status) else: date_completed = datetime.datetime.now(UTC) self.record_activity(date_started, date_completed) finally: install_feature_controller(original_feature_controller) if profiler: profiler.dump_stats(self.options.profile)
def _new_controller(script_name): controller = make_script_feature_controller(script_name) controller.getAllFlags() # Pull everything so future lookups don't block. return controller