예제 #1
0
    def queue(self, workflow_invocation, request_params):
        workflow_invocation.state = model.WorkflowInvocation.states.NEW
        scheduler = request_params.get("scheduler",
                                       None) or self.default_scheduler_id
        handler = self._get_handler(workflow_invocation.history.id)

        if handler is None and not self.__use_stack_messages:
            raise RuntimeError(
                "Unable to set a handler for workflow invocation '%s'" %
                workflow_invocation.id)

        log.info("Queueing workflow invocation for handler [%s]", handler)
        workflow_invocation.scheduler = scheduler
        workflow_invocation.handler = handler

        sa_session = self.app.model.context
        sa_session.add(workflow_invocation)
        sa_session.flush()

        if handler is None and self.__use_stack_messages:
            log.info(
                "(%s) Queueing workflow invocation via stack messaging for pool [%s]",
                workflow_invocation.id, self.__handler_pool)
            msg = WorkflowSchedulingMessage(
                task='setup', workflow_invocation_id=workflow_invocation.id)
            self.app.application_stack.send_message(self.__handler_pool, msg)

        return workflow_invocation
예제 #2
0
 def __startup_recovery(self):
     sa_session = self.app.model.context
     if self.__use_stack_messages:
         for workflow_invocation in model.WorkflowInvocation.poll_active_workflow_ids(
                 sa_session,
                 handler=None):
             log.info("(%s) Handler unassigned at startup, queueing workflow invocation via stack messaging for pool"
                      " [%s]", workflow_invocation.id, self.__handler_pool)
             msg = WorkflowSchedulingMessage(task='setup', workflow_invocation_id=workflow_invocation.id)
             self.app.application_stack.send_message(self.app.application_stack.pools.JOB_HANDLERS, msg)
예제 #3
0
    def __init__(self, app):
        self.app = app
        self.__handlers_configured = False
        self.workflow_schedulers = {}
        self.active_workflow_schedulers = {}
        # Passive workflow schedulers won't need to be monitored I guess.

        self.request_monitor = None

        self.handlers = {}
        self.handler_assignment_methods_configured = False
        self.handler_assignment_methods = None
        self.handler_max_grab = 1
        self.default_handler_id = None

        self.__plugin_classes = self.__plugins_dict()
        self.__init_schedulers()

        if self._is_workflow_handler():
            log.debug("Starting workflow schedulers")
            self.__start_schedulers()
            if self.active_workflow_schedulers:
                self.__start_request_monitor()

        # When assinging handlers to workflows being queued - use job_conf
        # if not explicit workflow scheduling handlers have be specified or
        # else use those explicit workflow scheduling handlers (on self).
        if self.__handlers_configured:
            self.__handlers_config = self
        else:
            self.__handlers_config = app.job_config

        if self._is_workflow_handler():
            if self.__handlers_config.use_messaging:
                WorkflowSchedulingMessage().bind_default_handler(
                    self, '_handle_message')
                self.app.application_stack.register_message_handler(
                    self._handle_message,
                    name=WorkflowSchedulingMessage.target)
        else:
            # Process should not schedule workflows but should check for any unassigned to handlers
            self.__startup_recovery()
예제 #4
0
    def __init__(self, app):
        self.app = app
        self.__handlers_configured = False
        self.workflow_schedulers = {}
        self.active_workflow_schedulers = {}
        # TODO: this should not hardcode the job handlers pool
        self.__handler_pool = self.app.application_stack.pools.JOB_HANDLERS
        # TODO: and we need a better way to indicate messaging should be used
        self.__use_stack_messages = app.application_stack.has_pool(
            self.__handler_pool)
        # Passive workflow schedulers won't need to be monitored I guess.

        self.request_monitor = None

        self.handlers = {}
        self._is_handler = None

        self.__plugin_classes = self.__plugins_dict()
        self.__init_schedulers()

        if self._is_workflow_handler():
            log.debug("Starting workflow schedulers")
            self.__start_schedulers()
            if self.active_workflow_schedulers:
                self.__start_request_monitor()
            if self.__use_stack_messages:
                WorkflowSchedulingMessage().bind_default_handler(
                    self, '_handle_message')
                self.app.application_stack.register_message_handler(
                    self._handle_message,
                    name=WorkflowSchedulingMessage.target)
        else:
            # Process should not schedule workflows but should check for any unassigned to handlers
            self.__startup_recovery()

        # When assinging handlers to workflows being queued - use job_conf
        # if not explicit workflow scheduling handlers have be specified or
        # else use those explicit workflow scheduling handlers (on self).
        if self.__handlers_configured:
            self.__has_handlers = self
        else:
            self.__has_handlers = app.job_config
예제 #5
0
 def _message_callback(self, workflow_invocation):
     return WorkflowSchedulingMessage(
         task='setup', workflow_invocation_id=workflow_invocation.id)