예제 #1
0
파일: maaps.py 프로젝트: hdj666/maaps
    def __init__(self, name, application, step_type, step_subtype, step_content, shared_lock):
        super(StepEntrypoint, self).__init__(name, application, step_type, step_subtype, step_content, shared_lock)
        self.logger        = logging.getLogger('maaps.ep')
        self.is_entrypoint = True
        self.instance      = None

        atexit.register(self.shutdown)

        self.apply_assignements_to_context()

        if self.sub_stype == 'HttpListener':
            self.logger   = logging.getLogger('maaps.ep.httplistener')
            self.instance = EPHttpListener(self.local_context, self.name)
        elif self.sub_stype == 'LOOP':
            self.logger = logging.getLogger('maaps.ep.loop')

            assert('code' in self.local_context)

            source_code = PyCode.tidy_source_code(self.local_context['code'])
            if not source_code:
                raise SyntaxError("%s: No CODE/CONTEXT block in LOOP statement!", self.name)

            self.local_context[CTX_LOCK] = self.shared_lock

            self.instance = EPLoop(self.local_context, self.name, source_code)

        else:
            raise TypeError('%s: unknown entrypoint-type "%s"' % (self.name, self.sub_stype,))
예제 #2
0
파일: maaps.py 프로젝트: hdj666/maaps
class StepEntrypoint(StepBase):
    def __init__(self, name, application, step_type, step_subtype, step_content, shared_lock):
        super(StepEntrypoint, self).__init__(name, application, step_type, step_subtype, step_content, shared_lock)
        self.logger        = logging.getLogger('maaps.ep')
        self.is_entrypoint = True
        self.instance      = None

        atexit.register(self.shutdown)

        self.apply_assignements_to_context()

        if self.sub_stype == 'HttpListener':
            self.logger   = logging.getLogger('maaps.ep.httplistener')
            self.instance = EPHttpListener(self.local_context, self.name)
        elif self.sub_stype == 'LOOP':
            self.logger = logging.getLogger('maaps.ep.loop')

            assert('code' in self.local_context)

            source_code = PyCode.tidy_source_code(self.local_context['code'])
            if not source_code:
                raise SyntaxError("%s: No CODE/CONTEXT block in LOOP statement!", self.name)

            self.local_context[CTX_LOCK] = self.shared_lock

            self.instance = EPLoop(self.local_context, self.name, source_code)

        else:
            raise TypeError('%s: unknown entrypoint-type "%s"' % (self.name, self.sub_stype,))

    def run(self, runtime_context):
        result = self.instance.wait4data(runtime_context)
        self.logger.info('%s: "payload" from EP: %r', self.name, result)
        #self.logger.debug('%s: and context is "%r".', self.name, runtime_context)
        return result

    def shutdown(self):
        self.logger.info('%s: Running SHUTDOWN!', self.name)
        success = self.instance.shutdown()
        if success:
            self.logger.info('%s: Instance shutdown successfull.', self.name)
        else:
            self.logger.error('%s: Failed to shutdown instance!', self.name)