PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/boto-2.5.2/boto/swf/layer1_decisions.py

#
Python | 316 lines | 189 code | 17 blank | 110 comment | 32 complexity | 4107feeaf8c9aeb5bd516a9fea7bdba2 MD5 | raw file
  1. """
  2. helper class for creating decision responses
  3. """
  4. class Layer1Decisions:
  5. """
  6. Use this object to build a list of decisions for a decision response.
  7. Each method call will add append a new decision. Retrieve the list
  8. of decisions from the _data attribute.
  9. """
  10. def __init__(self):
  11. self._data = []
  12. def schedule_activity_task(self,
  13. activity_id,
  14. activity_type_name,
  15. activity_type_version,
  16. task_list=None,
  17. control=None,
  18. heartbeat_timeout=None,
  19. schedule_to_close_timeout=None,
  20. schedule_to_start_timeout=None,
  21. start_to_close_timeout=None,
  22. input=None):
  23. """
  24. schedules an activity task
  25. :type activity_id: string
  26. :param activity_id: The activityId of the type of the activity
  27. being scheduled.
  28. :type activity_type_name: string
  29. :param activity_type_name: The name of the type of the activity
  30. being scheduled.
  31. :type activity_type_version: string
  32. :param activity_type_version: The version of the type of the
  33. activity being scheduled.
  34. :type task_list: string
  35. :param task_list: If set, specifies the name of the task list in
  36. which to schedule the activity task. If not specified, the
  37. defaultTaskList registered with the activity type will be used.
  38. Note: a task list for this activity task must be specified either
  39. as a default for the activity type or through this field. If
  40. neither this field is set nor a default task list was specified
  41. at registration time then a fault will be returned.
  42. FINISH DOCS
  43. """
  44. o = {}
  45. o['decisionType'] = 'ScheduleActivityTask'
  46. attrs = o['scheduleActivityTaskDecisionAttributes'] = {}
  47. attrs['activityId'] = activity_id
  48. attrs['activityType'] = {
  49. 'name': activity_type_name,
  50. 'version': activity_type_version,
  51. }
  52. if task_list is not None:
  53. attrs['taskList'] = {'name': task_list}
  54. if control is not None:
  55. attrs['control'] = control
  56. if heartbeat_timeout is not None:
  57. attrs['heartbeatTimeout'] = heartbeat_timeout
  58. if schedule_to_close_timeout is not None:
  59. attrs['scheduleToCloseTimeout'] = schedule_to_close_timeout
  60. if schedule_to_start_timeout is not None:
  61. attrs['scheduleToStartTimeout'] = schedule_to_start_timeout
  62. if start_to_close_timeout is not None:
  63. attrs['startToCloseTimeout'] = start_to_close_timeout
  64. if input is not None:
  65. attrs['input'] = input
  66. self._data.append(o)
  67. def request_cancel_activity_task(self,
  68. activity_id):
  69. """
  70. attempts to cancel a previously scheduled activity task. If the activity
  71. task was scheduled but has not been assigned to a worker, then it will
  72. be canceled. If the activity task was already assigned to a worker, then
  73. the worker will be informed that cancellation has been requested in the
  74. response to RecordActivityTaskHeartbeat.
  75. FINISH DOCS
  76. """
  77. o = {}
  78. o['decisionType'] = 'RequestCancelActivityTask'
  79. attrs = o['requestCancelActivityTaskDecisionAttributes'] = {}
  80. attrs['activityId'] = activity_id
  81. self._data.append(o)
  82. def record_marker(self,
  83. marker_name,
  84. details=None):
  85. """
  86. records a MarkerRecorded event in the history. Markers can be used for
  87. adding custom information in the history for instance to let deciders know
  88. that they do not need to look at the history beyond the marker event.
  89. FINISH DOCS
  90. """
  91. o = {}
  92. o['decisionType'] = 'RecordMarker'
  93. attrs = o['recordMarkerDecisionAttributes'] = {}
  94. attrs['markerName'] = marker_name
  95. if details is not None:
  96. attrs['details'] = details
  97. self._data.append(o)
  98. def complete_workflow_execution(self,
  99. result=None):
  100. """
  101. closes the workflow execution and records a WorkflowExecutionCompleted
  102. event in the history
  103. FINISH DOCS
  104. """
  105. o = {}
  106. o['decisionType'] = 'CompleteWorkflowExecution'
  107. attrs = o['completeWorkflowExecutionDecisionAttributes'] = {}
  108. if result is not None:
  109. attrs['result'] = result
  110. self._data.append(o)
  111. def fail_workflow_execution(self,
  112. reason=None,
  113. details=None):
  114. """
  115. closes the workflow execution and records a WorkflowExecutionFailed event
  116. in the history.
  117. FINISH DOCS
  118. """
  119. o = {}
  120. o['decisionType'] = 'FailWorkflowExecution'
  121. attrs = o['failWorkflowExecutionDecisionAttributes'] = {}
  122. if reason is not None:
  123. attrs['reason'] = reason
  124. if details is not None:
  125. attrs['details'] = details
  126. self._data.append(o)
  127. def cancel_workflow_executions(self,
  128. details=None):
  129. """
  130. closes the workflow execution and records a WorkflowExecutionCanceled
  131. event in the history.
  132. FINISH DOCS
  133. """
  134. o = {}
  135. o['decisionType'] = 'CancelWorkflowExecutions'
  136. attrs = o['cancelWorkflowExecutionsDecisionAttributes'] = {}
  137. if details is not None:
  138. attrs['details'] = details
  139. self._data.append(o)
  140. def continue_as_new_workflow_execution(self,
  141. child_policy=None,
  142. execution_start_to_close_timeout=None,
  143. input=None,
  144. tag_list=None,
  145. task_list=None,
  146. start_to_close_timeout=None,
  147. workflow_type_version=None):
  148. """
  149. closes the workflow execution and starts a new workflow execution of
  150. the same type using the same workflow id and a unique run Id. A
  151. WorkflowExecutionContinuedAsNew event is recorded in the history.
  152. FINISH DOCS
  153. """
  154. o = {}
  155. o['decisionType'] = 'ContinueAsNewWorkflowExecution'
  156. attrs = o['continueAsNewWorkflowExecutionDecisionAttributes'] = {}
  157. if child_policy is not None:
  158. attrs['childPolicy'] = child_policy
  159. if execution_start_to_close_timeout is not None:
  160. attrs['executionStartToCloseTimeout'] = execution_start_to_close_timeout
  161. if input is not None:
  162. attrs['input'] = input
  163. if tag_list is not None:
  164. attrs['tagList'] = tag_list
  165. if task_list is not None:
  166. attrs['taskList'] = {'name': task_list}
  167. if start_to_close_timeout is not None:
  168. attrs['startToCloseTimeout'] = start_to_close_timeout
  169. if workflow_type_version is not None:
  170. attrs['workflowTypeVersion'] = workflow_type_version
  171. self._data.append(o)
  172. def start_timer(self,
  173. start_to_fire_timeout,
  174. timer_id,
  175. control=None):
  176. """
  177. starts a timer for this workflow execution and records a TimerStarted
  178. event in the history. This timer will fire after the specified delay
  179. and record a TimerFired event.
  180. FINISH DOCS
  181. """
  182. o = {}
  183. o['decisionType'] = 'StartTimer'
  184. attrs = o['startTimerDecisionAttributes'] = {}
  185. attrs['startToFireTimeout'] = start_to_fire_timeout
  186. attrs['timerId'] = timer_id
  187. if control is not None:
  188. attrs['control'] = control
  189. self._data.append(o)
  190. def cancel_timer(self,
  191. timer_id):
  192. """
  193. cancels a previously started timer and records a TimerCanceled event in the
  194. history.
  195. FINISH DOCS
  196. """
  197. o = {}
  198. o['decisionType'] = 'CancelTimer'
  199. attrs = o['cancelTimerDecisionAttributes'] = {}
  200. attrs['timerId'] = timer_id
  201. self._data.append(o)
  202. def signal_external_workflow_execution(self,
  203. workflow_id,
  204. signal_name,
  205. run_id=None,
  206. control=None,
  207. input=None):
  208. """
  209. requests a signal to be delivered to the specified external workflow
  210. execution and records a SignalExternalWorkflowExecutionInitiated
  211. event in the history.
  212. FINISH DOCS
  213. """
  214. o = {}
  215. o['decisionType'] = 'SignalExternalWorkflowExecution'
  216. attrs = o['signalExternalWorkflowExecutionDecisionAttributes'] = {}
  217. attrs['workflowId'] = workflow_id
  218. attrs['signalName'] = signal_name
  219. if run_id is not None:
  220. attrs['runId'] = run_id
  221. if control is not None:
  222. attrs['control'] = control
  223. if input is not None:
  224. attrs['input'] = input
  225. self._data.append(o)
  226. def request_cancel_external_workflow_execution(self,
  227. workflow_id,
  228. control=None,
  229. run_id=None):
  230. """
  231. requests that a request be made to cancel the specified external workflow
  232. execution and records a
  233. RequestCancelExternalWorkflowExecutionInitiated event in the history.
  234. FINISH DOCS
  235. """
  236. o = {}
  237. o['decisionType'] = 'RequestCancelExternalWorkflowExecution'
  238. attrs = o['requestCancelExternalWorkflowExecutionDecisionAttributes'] = {}
  239. attrs['workflowId'] = workflow_id
  240. if control is not None:
  241. attrs['control'] = control
  242. if run_id is not None:
  243. attrs['runId'] = run_id
  244. self._data.append(o)
  245. def start_child_workflow_execution(self,
  246. workflow_type_name,
  247. workflow_type_version,
  248. child_policy=None,
  249. control=None,
  250. execution_start_to_close_timeout=None,
  251. input=None,
  252. tag_list=None,
  253. task_list=None,
  254. task_start_to_close_timeout=None):
  255. """
  256. requests that a child workflow execution be started and records a
  257. StartChildWorkflowExecutionInitiated event in the history. The child
  258. workflow execution is a separate workflow execution with its own history.
  259. FINISH DOCS
  260. """
  261. o = {}
  262. o['decisionType'] = 'StartChildWorkflowExecution'
  263. attrs = o['startChildWorkflowExecutionDecisionAttributes'] = {}
  264. attrs['workflowType'] = {
  265. 'name': workflow_type_name,
  266. 'version': workflow_type_version,
  267. }
  268. if child_policy is not None:
  269. attrs['childPolicy'] = child_policy
  270. if control is not None:
  271. attrs['control'] = control
  272. if execution_start_to_close_timeout is not None:
  273. attrs['executionStartToCloseTimeout'] = execution_start_to_close_timeout
  274. if input is not None:
  275. attrs['input'] = input
  276. if tag_list is not None:
  277. attrs['tagList'] = tag_list
  278. if task_list is not None:
  279. attrs['taskList'] = {'name': task_list}
  280. if task_start_to_close_timeout is not None:
  281. attrs['taskStartToCloseTimeout'] = task_start_to_close_timeout
  282. self._data.append(o)