Exemple #1
0
    def run_forever(self,
                    domain,
                    task_list,
                    swf_client=None,
                    setup_log=True,
                    register_remote=True,
                    identity=None):
        """Same as SWFWorkflowWorker.run_forever but for activities."""
        if setup_log:
            setup_default_logger()
        identity = default_identity() if identity is None else identity
        swf_client = SWFClient() if swf_client is None else swf_client
        if register_remote:
            self.register_remote(swf_client, domain)
        try:
            while 1:
                if self.break_loop():
                    break
                swf_response = {}
                while not swf_response.get('taskToken'):
                    try:
                        swf_response = swf_client.poll_for_activity_task(
                            domain, task_list, identity=identity)
                    except ClientError:
                        # add a delay before retrying?
                        logger.exception('Error while polling for activities:')

                at = swf_response['activityType']
                decision = SWFActivityDecision(swf_client,
                                               swf_response['taskToken'])
                self(at['name'], at['version'], swf_response['input'],
                     decision)
        except KeyboardInterrupt:
            pass
Exemple #2
0
    def run_forever(self, domain, task_list,
                    swf_client=None,
                    setup_log=True,
                    register_remote=True,
                    identity=None):
        """Same as SWFWorkflowWorker.run_forever but for activities."""
        if setup_log:
            setup_default_logger()
        identity = default_identity() if identity is None else identity
        swf_client = SWFClient() if swf_client is None else swf_client
        if register_remote:
            self.register_remote(swf_client, domain)
        try:
            while 1:
                if self.break_loop():
                    break
                swf_response = {}
                while not swf_response.get('taskToken'):
                    try:
                        swf_response = swf_client.poll_for_activity_task(
                            domain, task_list, identity=identity)
                    except ClientError:
                        # add a delay before retrying?
                        logger.exception('Error while polling for activities:')

                at = swf_response['activityType']
                decision = SWFActivityDecision(swf_client, swf_response['taskToken'])
                self(at['name'], at['version'], swf_response['input'], decision)
        except KeyboardInterrupt:
            pass
Exemple #3
0
    def run_forever(self, domain, task_list,
                    layer1=None,
                    setup_log=True,
                    register_remote=True,
                    identity=None):
        """Same as SWFWorkflowWorker.run_forever but for activities."""
        if setup_log:
            setup_default_logger()
        identity = identity if identity is not None else default_identity()
        identity = str(identity)[:_IDENTITY_SIZE]
        layer1 = layer1 if layer1 is not None else Layer1()
        if register_remote:
            self.register_remote(layer1, domain)
        try:
            while 1:
                if self.break_loop():
                    break
                swf_response = {}
                while ('taskToken' not in swf_response or not swf_response['taskToken']):
                    try:
                        swf_response = layer1.poll_for_activity_task(
                            domain=domain,
                            task_list=task_list,
                            identity=identity)
                    except SWFResponseError:
                        # add a delay before retrying?
                        logger.exception('Error while polling for activities:')

                at = swf_response['activityType']
                decision = SWFActivityDecision(layer1, swf_response['taskToken'])
                self(at['name'], at['version'], swf_response['input'], decision)
        except KeyboardInterrupt:
            pass
Exemple #4
0
def main():
    # logging, the basicConfig is for futures, setup_default_logger is for flowy
    logging.basicConfig()
    setup_default_logger()

    def workflow(workflow_class):
        try:
            return globals()[workflow_class]
        except KeyError:
            raise ValueError('Workflow "%s" not found.' % workflow_class)

    parser = argparse.ArgumentParser(description='Example workflow runner.')
    parser.add_argument('workflow', action='store', type=workflow)
    parser.add_argument('--pure', action='store_true', default=False)
    parser.add_argument('--workflow-workers',
                        action='store',
                        type=int,
                        default=2)
    parser.add_argument('--activity-workers',
                        action='store',
                        type=int,
                        default=8)
    parser.add_argument('--timeit', action='store_true', default=False)
    parser.add_argument('--trace', action='store_true', default=False)
    parser.add_argument('--wait-children', action='store_true', default=False)
    args = parser.parse_args()

    start = time.time()
    if args.pure:
        wf = args.workflow(activity)
        result = wf()
    else:
        lw = LocalWorkflow(args.workflow,
                           activity_workers=args.activity_workers,
                           workflow_workers=args.workflow_workers)
        lw.conf_activity('a', activity)
        result = lw.run(_wait=args.wait_children, _trace=args.trace)
    if args.timeit:
        print('Timed at:', time.time() - start)
    print('Result:', result)
Exemple #5
0
def main():
    # logging, the basicConfig is for futures, setup_default_logger is for flowy
    logging.basicConfig()
    setup_default_logger()

    def workflow(workflow_class):
        try:
            return globals()[workflow_class]
        except KeyError:
            raise ValueError('Workflow "%s" not found.' % workflow_class)

    parser = argparse.ArgumentParser(description='Example workflow runner.')
    parser.add_argument('workflow', action='store', type=workflow)
    parser.add_argument('--pure', action='store_true', default=False)
    parser.add_argument('--workflow-workers',
                        action='store',
                        type=int,
                        default=2)
    parser.add_argument('--activity-workers',
                        action='store',
                        type=int,
                        default=8)
    parser.add_argument('--timeit', action='store_true', default=False)
    parser.add_argument('--trace', action='store_true', default=False)
    parser.add_argument('--wait-children', action='store_true', default=False)
    args = parser.parse_args()

    start = time.time()
    if args.pure:
        wf = args.workflow(activity)
        result = wf()
    else:
        lw = LocalWorkflow(args.workflow,
                           activity_workers=args.activity_workers,
                           workflow_workers=args.workflow_workers)
        lw.conf_activity('a', activity)
        result = lw.run(_wait=args.wait_children, _trace=args.trace)
    if args.timeit:
        print('Timed at:', time.time() - start)
    print('Result:', result)
Exemple #6
0
    def run_forever(self,
                    domain,
                    task_list,
                    swf_client=None,
                    setup_log=True,
                    register_remote=True,
                    identity=None):
        """Starts an endless single threaded/single process worker loop.

        The worker polls endlessly for new decisions from the specified domain
        and task list and runs them.

        If reg_remote is set, all registered workflow are registered remotely.

        An identity can be set to track this worker in the SWF console,
        otherwise a default identity is generated from this machine domain and
        process pid.

        If setup_log is set, a default configuration for the logger is loaded.

        A custom SWF client can be passed in swf_client, otherwise a default
        client is used.
        """
        if setup_log:
            setup_default_logger()
        identity = default_identity() if identity is None else identity
        swf_client = SWFClient() if swf_client is None else swf_client
        if register_remote:
            self.register_remote(swf_client, domain)
        try:
            while 1:
                if self.break_loop():
                    break
                name, version, input_data, exec_history, decision = poll_decision(
                    swf_client, domain, task_list, identity)
                self(name, version, input_data, decision, exec_history)
        except KeyboardInterrupt:
            pass
Exemple #7
0
    def run_forever(self, domain, task_list,
                    layer1=None,
                    setup_log=True,
                    register_remote=True,
                    identity=None):
        """Start an endless single threaded/single process worker loop.

        The worker polls endlessly for new decisions from the specified domain
        and task list and runs them.

        If reg_remote is set, all registered workflow are registered remotely.

        An identity can be set to track this worker in the SWF console,
        otherwise a default identity is generated from this machine domain and
        process pid.

        If setup_log is set, a default configuration for the logger is loaded.

        A custom SWF client can be passed in layer1, otherwise a default client
        is used.

        """
        if setup_log:
            setup_default_logger()
        identity = identity if identity is not None else default_identity()
        identity = str(identity)[:_IDENTITY_SIZE]
        layer1 = layer1 if layer1 is not None else Layer1()
        if register_remote:
            self.register_remote(layer1, domain)
        try:
            while 1:
                if self.break_loop():
                    break
                name, version, input_data, exec_history, decision = poll_decision(
                    layer1, domain, task_list, identity)
                self(name, version, input_data, decision, exec_history)
        except KeyboardInterrupt:
            pass