Example #1
0
 def _deco(*args, **kwargs):
     try:
         func(*args, **kwargs)
     except Exception:
         raise
     finally:
         G.getInstance().close()
Example #2
0
    def run(self):
        """ 开始执行 """
        invoker_prefix = str(self._executor).capitalize()
        controller = "{invoker}Controller".format(invoker=invoker_prefix)

        executor = __import__(
            "controllers.{invoker}".format(invoker=invoker_prefix),
            fromlist=controller)
        executor_obj = eval("executor.{controller}.getInstance()".format(
            controller=controller))

        if self._method is None:
            if hasattr(executor_obj, 'default_method'):
                self._method = executor_obj.default_method.lower()

        try:
            executor_obj.prepare()
            method = getattr(executor_obj, self._method)
            method(*self._args, **self._kwargs)
        except Exception:
            raise
        finally:
            if not G.getInstance().is_cleard:
                with closing(G.getInstance()):
                    pass
Example #3
0
 def _deco(*args, **kwargs):
     try:
         func(*args, **kwargs)
     except Exception as e:
         raise e
     finally:
         G.getInstance().clear()
#!/usr/bin/env python

from library.Decorate import DI
from library.G import G


@DI(g=G.getInstance())
class BaseService(object):
    @property
    def session(self):
        return self.g.session

    @property
    def utils(self):
        return self.g.utils

    @property
    def redis(self):
        return self.g.redis

    @property
    def mongo(self):
        return self.g.mongo

    @property
    def rpc(self):
        return self.g.rpc

    @property
    def conf(self):
        return self.g.conf
Example #5
0
 def on_finish(self):
     """ 清理资源 """
     G.getInstance().clear()