| 
									
										
										
										
											2015-10-26 18:05:45 +01:00
										 |  |  | import boto | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  | from moto.swf.models import ( | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  |     ActivityType, | 
					
						
							| 
									
										
										
										
											2015-10-25 11:30:11 +01:00
										 |  |  |     Domain, | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  |     WorkflowType, | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  |     WorkflowExecution, | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | # Some useful constants | 
					
						
							|  |  |  | # Here are some activity timeouts we use in moto/swf tests ; they're extracted | 
					
						
							|  |  |  | # from semi-real world example, the goal is mostly to have predictible and | 
					
						
							|  |  |  | # intuitive behaviour in moto/swf own tests... | 
					
						
							|  |  |  | ACTIVITY_TASK_TIMEOUTS = { | 
					
						
							|  |  |  |     "heartbeatTimeout": "300",        # 5 mins | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     "scheduleToStartTimeout": "1800",  # 30 mins | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  |     "startToCloseTimeout": "1800",    # 30 mins | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |     "scheduleToCloseTimeout": "2700",  # 45 mins | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Some useful decisions | 
					
						
							|  |  |  | SCHEDULE_ACTIVITY_TASK_DECISION = { | 
					
						
							|  |  |  |     "decisionType": "ScheduleActivityTask", | 
					
						
							|  |  |  |     "scheduleActivityTaskDecisionAttributes": { | 
					
						
							|  |  |  |         "activityId": "my-activity-001", | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  |         "activityType": {"name": "test-activity", "version": "v1.1"}, | 
					
						
							|  |  |  |         "taskList": {"name": "activity-task-list"}, | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-03 09:17:56 +01:00
										 |  |  | for key, value in ACTIVITY_TASK_TIMEOUTS.items(): | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     SCHEDULE_ACTIVITY_TASK_DECISION[ | 
					
						
							|  |  |  |         "scheduleActivityTaskDecisionAttributes"][key] = value | 
					
						
							| 
									
										
										
										
											2015-11-03 00:28:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-25 11:30:11 +01:00
										 |  |  | # A test Domain | 
					
						
							|  |  |  | def get_basic_domain(): | 
					
						
							|  |  |  |     return Domain("test-domain", "90") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | # A test WorkflowType | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  | def _generic_workflow_type_attributes(): | 
					
						
							|  |  |  |     return [ | 
					
						
							|  |  |  |         "test-workflow", "v1.0" | 
					
						
							|  |  |  |     ], { | 
					
						
							|  |  |  |         "task_list": "queue", | 
					
						
							|  |  |  |         "default_child_policy": "ABANDON", | 
					
						
							| 
									
										
										
										
											2015-11-04 22:03:58 +01:00
										 |  |  |         "default_execution_start_to_close_timeout": "7200", | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  |         "default_task_start_to_close_timeout": "300", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  | def get_basic_workflow_type(): | 
					
						
							|  |  |  |     args, kwargs = _generic_workflow_type_attributes() | 
					
						
							|  |  |  |     return WorkflowType(*args, **kwargs) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-02 14:02:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-04 23:37:50 +02:00
										 |  |  | def mock_basic_workflow_type(domain_name, conn): | 
					
						
							|  |  |  |     args, kwargs = _generic_workflow_type_attributes() | 
					
						
							|  |  |  |     conn.register_workflow_type(domain_name, *args, **kwargs) | 
					
						
							|  |  |  |     return conn | 
					
						
							| 
									
										
										
										
											2015-10-26 06:31:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # A test WorkflowExecution | 
					
						
							|  |  |  | def make_workflow_execution(**kwargs): | 
					
						
							|  |  |  |     domain = get_basic_domain() | 
					
						
							|  |  |  |     domain.add_type(ActivityType("test-activity", "v1.1")) | 
					
						
							|  |  |  |     wft = get_basic_workflow_type() | 
					
						
							|  |  |  |     return WorkflowExecution(domain, wft, "ab1234", **kwargs) | 
					
						
							| 
									
										
										
										
											2015-10-26 18:05:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-09 23:44:49 +01:00
										 |  |  | # Makes decision tasks start automatically on a given workflow | 
					
						
							|  |  |  | def auto_start_decision_tasks(wfe): | 
					
						
							|  |  |  |     wfe.schedule_decision_task = wfe.schedule_and_start_decision_task | 
					
						
							|  |  |  |     return wfe | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 18:05:45 +01:00
										 |  |  | # Setup a complete example workflow and return the connection object | 
					
						
							|  |  |  | def setup_workflow(): | 
					
						
							|  |  |  |     conn = boto.connect_swf("the_key", "the_secret") | 
					
						
							|  |  |  |     conn.register_domain("test-domain", "60", description="A test domain") | 
					
						
							|  |  |  |     conn = mock_basic_workflow_type("test-domain", conn) | 
					
						
							|  |  |  |     conn.register_activity_type( | 
					
						
							|  |  |  |         "test-domain", "test-activity", "v1.1", | 
					
						
							|  |  |  |         default_task_heartbeat_timeout="600", | 
					
						
							|  |  |  |         default_task_schedule_to_close_timeout="600", | 
					
						
							|  |  |  |         default_task_schedule_to_start_timeout="600", | 
					
						
							|  |  |  |         default_task_start_to_close_timeout="600", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     wfe = conn.start_workflow_execution( | 
					
						
							|  |  |  |         "test-domain", "uid-abcd1234", "test-workflow", "v1.0") | 
					
						
							| 
									
										
										
										
											2015-10-26 18:05:45 +01:00
										 |  |  |     conn.run_id = wfe["runId"] | 
					
						
							|  |  |  |     return conn | 
					
						
							| 
									
										
										
										
											2015-11-05 02:47:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # A helper for processing the first timeout on a given object | 
					
						
							|  |  |  | def process_first_timeout(obj): | 
					
						
							|  |  |  |     _timeout = obj.first_timeout() | 
					
						
							|  |  |  |     if _timeout: | 
					
						
							|  |  |  |         obj.timeout(_timeout) |