from garcon import activity from garcon import runner from garcon import param import tasks class ComponentV1(object): def __init__(self, create_activity): """Create a WorkFlow flow. Args: create_activity (func): garcon.activity.create function. """ self.create = create_activity def hello_activity( self, activity_name, sleep_time, context_id='bootstrap.id', namespace_task_1=None, namespace_task_2=None): """Create a WorkFlow flow. Args: activity_name (str): name of activity. sleep_time (int): length of time that the first task sleeps for. context_id (str): identifier for workflow printed by tasks. namespace_task_1 (str): namespace for first task. namespace_task_2 (str): namespace for second task. """ namespace_task_1 = namespace_task_1 or '{}_task_one'.format( activity_name) namespace_task_2 = namespace_task_1 or '{}_task_two'.format( activity_name) print('sleep set for {}'.format(sleep_time)) return self.create( name=activity_name, #'hello_world_five', tasks=runner.Async( tasks.print_hello_task.fill( namespace=namespace_task_1, #'activity_five_task_one', workflow_id=context_id, sleep=param.StaticParam(sleep_time), activity_name=param.StaticParam(activity_name), task_name=param.StaticParam('Task 1')), tasks.print_hello_task.fill( namespace=namespace_task_2, #'activity_five_task_two', workflow_id=context_id, activity_name=param.StaticParam(activity_name), task_name=param.StaticParam('Task 2')))) class ComponentV2(object): def __init__(self, name, domain, version): """Create a WorkFlow flow. Args: name (str): name of workflow. domain (str): domain workflow runs under. version (str): version of the workflow (ex 1.0). """ self.create = activity.create( self.domain, self.name, version=self.version, on_exception=self.on_exception) def hello_activity( self, activity_name, sleep_time, context_id='bootstrap.id', namespace_task_1=None, namespace_task_2=None): """Create a WorkFlow flow. Args: activity_name (str): name of activity. sleep_time (int): length of time that the first task sleeps for. context_id (str): identifier for workflow printed by tasks. namespace_task_1 (str): namespace for first task. namespace_task_2 (str): namespace for second task. """ namespace_task_1 = namespace_task_1 or '{}_task_one'.format( activity_name) namespace_task_2 = namespace_task_1 or '{}_task_two'.format( activity_name) print('sleep set for {}'.format(sleep_time)) return self.create( name=activity_name, #'hello_world_five', tasks=runner.Async( tasks.print_hello_task.fill( namespace=namespace_task_1, #'activity_five_task_one', workflow_id=context_id, sleep=param.StaticParam(sleep_time), activity_name=param.StaticParam(activity_name), task_name=param.StaticParam('Task 1')), tasks.print_hello_task.fill( namespace=namespace_task_2, #'activity_five_task_two', workflow_id=context_id, activity_name=param.StaticParam(activity_name), task_name=param.StaticParam('Task 2'))))