Permalink
Browse files

job decorator

  • Loading branch information...
1 parent f620b9a commit 4b94e6f2a58dfe5b10769b7179adeb663c1991a2 @alexcepoi committed Feb 9, 2012
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import logging
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
from pyscale.tools.tasks import *
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
@@ -1,7 +1,7 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
-from pyscale.lib.module import BaseModule
+from pyscale.lib.module import BaseModule, job
class Module(BaseModule):
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
from pyscale.tools.logger import main
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
from .decorators import *
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
def api(method):
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
View
@@ -1,7 +1,8 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import inspect
+import types
import logging
import os
import os.path as osp
@@ -21,6 +22,11 @@
from config.app import Configuration
+def job(method):
+ method.job = True
+ return method
+
+
class BaseModule(object):
""" Basic Module Class (daemon) """
@@ -43,6 +49,15 @@ def __init__(self, context=None):
self.rpc = RpcServer(self, "ipc://tmp/sockets/rpc/%s.sock" % self.name)
self.rpc.run()
+ # spawn jobs
+ bases = self.__class__.__mro__
+ for base in bases:
+ for func in base.__dict__.values():
+ if getattr(func, 'job', None):
+ method = types.MethodType(func, self, self.__class__)
+ self.jobs.spawn(method)
+
+
def run(self):
""" Run the current module (start greenlets) """
# check for previous crash
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.6
+#!/usr/bin/python
# -*- coding: utf-8 -*-
from .commands import *
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.6
+#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess as sbp
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import logging
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import logging
@@ -55,7 +55,7 @@ def _run(self):
self.send(envelope, reply)
def handle(self, requests):
- logging.info("[zmq] <~ self%s" % ''.join([format_method(*req) for req in requests]))
+ logging.debug("[zmq] <~ self%s" % ''.join([format_method(*req) for req in requests]))
# loop request chain
module = self.server.module
View
@@ -1,4 +1,4 @@
-#! /usr/bin/env python2.6
+#! /usr/bin/env python
# -*- coding: utf-8 -*-
import logging
@@ -148,7 +148,7 @@ def __exit__(self, type, value, trace):
def _send(self, blob):
self._sock.send_json(blob)
- logging.info("[zmq] ~> %s%s" % (self._name, ''.join([format_method(*req) for req in blob])))
+ logging.debug("[zmq] ~> %s%s" % (self._name, ''.join([format_method(*req) for req in blob])))
return self._sock.recv_json()
# pass to proxy

0 comments on commit 4b94e6f

Please sign in to comment.