PageRenderTime 66ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/swf/layer1.py

#
Python | 1561 lines | 1508 code | 15 blank | 38 comment | 9 complexity | e24ad04478a4b095bdefef97f503ffdf MD5 | raw file
  1. # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
  2. # Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
  3. # All Rights Reserved
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the
  7. # "Software"), to deal in the Software without restriction, including
  8. # without limitation the rights to use, copy, modify, merge, publish, dis-
  9. # tribute, sublicense, and/or sell copies of the Software, and to permit
  10. # persons to whom the Software is furnished to do so, subject to the fol-
  11. # lowing conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included
  14. # in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  18. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  19. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. # IN THE SOFTWARE.
  23. #
  24. import boto
  25. from boto.connection import AWSAuthConnection
  26. from boto.provider import Provider
  27. from boto.exception import SWFResponseError
  28. from boto.swf import exceptions as swf_exceptions
  29. import time
  30. try:
  31. import simplejson as json
  32. except ImportError:
  33. import json
  34. #
  35. # To get full debug output, uncomment the following line and set the
  36. # value of Debug to be 2
  37. #
  38. #boto.set_stream_logger('swf')
  39. Debug=0
  40. class Layer1(AWSAuthConnection):
  41. """
  42. Low-level interface to Simple WorkFlow Service.
  43. """
  44. DefaultRegionName = 'us-east-1'
  45. """The default region name for Simple Workflow."""
  46. ServiceName = 'com.amazonaws.swf.service.model.SimpleWorkflowService'
  47. """The name of the Service"""
  48. # In some cases, the fault response __type value is mapped to
  49. # an exception class more specific than SWFResponseError.
  50. _fault_excp = {
  51. 'com.amazonaws.swf.base.model#DomainAlreadyExistsFault':
  52. swf_exceptions.SWFDomainAlreadyExistsError,
  53. 'com.amazonaws.swf.base.model#LimitExceededFault':
  54. swf_exceptions.SWFLimitExceededError,
  55. 'com.amazonaws.swf.base.model#OperationNotPermittedFault':
  56. swf_exceptions.SWFOperationNotPermittedError,
  57. 'com.amazonaws.swf.base.model#TypeAlreadyExistsFault':
  58. swf_exceptions.SWFTypeAlreadyExistsError,
  59. }
  60. ResponseError = SWFResponseError
  61. def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
  62. is_secure=True, port=None, proxy=None, proxy_port=None,
  63. debug=0, session_token=None, region=None):
  64. if not region:
  65. region_name = boto.config.get('SWF', 'region',
  66. self.DefaultRegionName)
  67. for reg in boto.swf.regions():
  68. if reg.name == region_name:
  69. region = reg
  70. break
  71. self.region = region
  72. AWSAuthConnection.__init__(self, self.region.endpoint,
  73. aws_access_key_id, aws_secret_access_key,
  74. is_secure, port, proxy, proxy_port,
  75. debug, session_token)
  76. def _required_auth_capability(self):
  77. return ['hmac-v3-http']
  78. def _credentials_expired(self, response):
  79. if response.status != 400:
  80. return False
  81. try:
  82. parsed = json.loads(response.read())
  83. # It seems that SWF doesn't really have a specific "Token Expired"
  84. # message, but this is a best effort heuristic.
  85. expected = 'com.amazon.coral.service#UnrecognizedClientException'
  86. return (parsed['__type'] == expected and \
  87. 'security token' in parsed['message'])
  88. except Exception, e:
  89. return False
  90. return False
  91. def make_request(self, action, body='', object_hook=None):
  92. """
  93. :raises: ``SWFResponseError`` if response status is not 200.
  94. """
  95. headers = {'X-Amz-Target': '%s.%s' % (self.ServiceName, action),
  96. 'Host': self.region.endpoint,
  97. 'Content-Type': 'application/json; charset=UTF-8',
  98. 'Content-Encoding': 'amz-1.0',
  99. 'Content-Length': str(len(body))}
  100. http_request = self.build_base_http_request('POST', '/', '/',
  101. {}, headers, body, None)
  102. response = self._mexe(http_request, sender=None,
  103. override_num_retries=10)
  104. response_body = response.read()
  105. boto.log.debug(response_body)
  106. if response.status == 200:
  107. if response_body:
  108. return json.loads(response_body, object_hook=object_hook)
  109. else:
  110. return None
  111. else:
  112. json_body = json.loads(response_body)
  113. fault_name = json_body.get('__type', None)
  114. # Certain faults get mapped to more specific exception classes.
  115. excp_cls = self._fault_excp.get(fault_name, self.ResponseError)
  116. raise excp_cls(response.status, response.reason, body=json_body)
  117. # Actions related to Activities
  118. def poll_for_activity_task(self, domain, task_list, identity=None):
  119. """
  120. Used by workers to get an ActivityTask from the specified
  121. activity taskList. This initiates a long poll, where the
  122. service holds the HTTP connection open and responds as soon as
  123. a task becomes available. The maximum time the service holds
  124. on to the request before responding is 60 seconds. If no task
  125. is available within 60 seconds, the poll will return an empty
  126. result. An empty result, in this context, means that an
  127. ActivityTask is returned, but that the value of taskToken is
  128. an empty string. If a task is returned, the worker should use
  129. its type to identify and process it correctly.
  130. :type domain: string
  131. :param domain: The name of the domain that contains the task
  132. lists being polled.
  133. :type task_list: string
  134. :param task_list: Specifies the task list to poll for activity tasks.
  135. :type identity: string
  136. :param identity: Identity of the worker making the request, which
  137. is recorded in the ActivityTaskStarted event in the workflow
  138. history. This enables diagnostic tracing when problems arise.
  139. The form of this identity is user defined.
  140. :raises: UnknownResourceFault, OperationNotPermittedFault
  141. """
  142. data = {'domain': domain, 'taskList': {'name': task_list}}
  143. if identity:
  144. data['identity'] = identity
  145. json_input = json.dumps(data)
  146. return self.make_request('PollForActivityTask', json_input)
  147. def respond_activity_task_completed(self, task_token, result=None):
  148. """
  149. Used by workers to tell the service that the ActivityTask
  150. identified by the taskToken completed successfully with a
  151. result (if provided).
  152. :type task_token: string
  153. :param task_token: The taskToken of the ActivityTask.
  154. :type result: string
  155. :param result: The result of the activity task. It is a free
  156. form string that is implementation specific.
  157. :raises: UnknownResourceFault, OperationNotPermittedFault
  158. """
  159. data = {'taskToken': task_token}
  160. if result:
  161. data['result'] = result
  162. json_input = json.dumps(data)
  163. return self.make_request('RespondActivityTaskCompleted', json_input)
  164. def respond_activity_task_failed(self, task_token,
  165. details=None, reason=None):
  166. """
  167. Used by workers to tell the service that the ActivityTask
  168. identified by the taskToken has failed with reason (if
  169. specified).
  170. :type task_token: string
  171. :param task_token: The taskToken of the ActivityTask.
  172. :type details: string
  173. :param details: Optional detailed information about the failure.
  174. :type reason: string
  175. :param reason: Description of the error that may assist in diagnostics.
  176. :raises: UnknownResourceFault, OperationNotPermittedFault
  177. """
  178. data = {'taskToken': task_token}
  179. if details:
  180. data['details'] = details
  181. if reason:
  182. data['reason'] = reason
  183. json_input = json.dumps(data)
  184. return self.make_request('RespondActivityTaskFailed', json_input)
  185. def respond_activity_task_canceled(self, task_token, details=None):
  186. """
  187. Used by workers to tell the service that the ActivityTask
  188. identified by the taskToken was successfully
  189. canceled. Additional details can be optionally provided using
  190. the details argument.
  191. :type task_token: string
  192. :param task_token: The taskToken of the ActivityTask.
  193. :type details: string
  194. :param details: Optional detailed information about the failure.
  195. :raises: UnknownResourceFault, OperationNotPermittedFault
  196. """
  197. data = {'taskToken': task_token}
  198. if details:
  199. data['details'] = details
  200. json_input = json.dumps(data)
  201. return self.make_request('RespondActivityTaskCanceled', json_input)
  202. def record_activity_task_heartbeat(self, task_token, details=None):
  203. """
  204. Used by activity workers to report to the service that the
  205. ActivityTask represented by the specified taskToken is still
  206. making progress. The worker can also (optionally) specify
  207. details of the progress, for example percent complete, using
  208. the details parameter. This action can also be used by the
  209. worker as a mechanism to check if cancellation is being
  210. requested for the activity task. If a cancellation is being
  211. attempted for the specified task, then the boolean
  212. cancelRequested flag returned by the service is set to true.
  213. :type task_token: string
  214. :param task_token: The taskToken of the ActivityTask.
  215. :type details: string
  216. :param details: If specified, contains details about the
  217. progress of the task.
  218. :raises: UnknownResourceFault, OperationNotPermittedFault
  219. """
  220. data = {'taskToken': task_token}
  221. if details:
  222. data['details'] = details
  223. json_input = json.dumps(data)
  224. return self.make_request('RecordActivityTaskHeartbeat', json_input)
  225. # Actions related to Deciders
  226. def poll_for_decision_task(self, domain, task_list, identity=None,
  227. maximum_page_size=None,
  228. next_page_token=None,
  229. reverse_order=None):
  230. """
  231. Used by deciders to get a DecisionTask from the specified
  232. decision taskList. A decision task may be returned for any
  233. open workflow execution that is using the specified task
  234. list. The task includes a paginated view of the history of the
  235. workflow execution. The decider should use the workflow type
  236. and the history to determine how to properly handle the task.
  237. :type domain: string
  238. :param domain: The name of the domain containing the task
  239. lists to poll.
  240. :type task_list: string
  241. :param task_list: Specifies the task list to poll for decision tasks.
  242. :type identity: string
  243. :param identity: Identity of the decider making the request,
  244. which is recorded in the DecisionTaskStarted event in the
  245. workflow history. This enables diagnostic tracing when
  246. problems arise. The form of this identity is user defined.
  247. :type maximum_page_size: integer :param maximum_page_size: The
  248. maximum number of history events returned in each page. The
  249. default is 100, but the caller can override this value to a
  250. page size smaller than the default. You cannot specify a page
  251. size greater than 100.
  252. :type next_page_token: string
  253. :param next_page_token: If on a previous call to this method a
  254. NextPageToken was returned, the results are being paginated.
  255. To get the next page of results, repeat the call with the
  256. returned token and all other arguments unchanged.
  257. :type reverse_order: boolean
  258. :param reverse_order: When set to true, returns the events in
  259. reverse order. By default the results are returned in
  260. ascending order of the eventTimestamp of the events.
  261. :raises: UnknownResourceFault, OperationNotPermittedFault
  262. """
  263. data = {'domain': domain, 'taskList': {'name': task_list}}
  264. if identity:
  265. data['identity'] = identity
  266. if maximum_page_size:
  267. data['maximumPageSize'] = maximum_page_size
  268. if next_page_token:
  269. data['nextPageToken'] = next_page_token
  270. if reverse_order:
  271. data['reverseOrder'] = 'true'
  272. json_input = json.dumps(data)
  273. return self.make_request('PollForDecisionTask', json_input)
  274. def respond_decision_task_completed(self, task_token,
  275. decisions=None,
  276. execution_context=None):
  277. """
  278. Used by deciders to tell the service that the DecisionTask
  279. identified by the taskToken has successfully completed.
  280. The decisions argument specifies the list of decisions
  281. made while processing the task.
  282. :type task_token: string
  283. :param task_token: The taskToken of the ActivityTask.
  284. :type decisions: list
  285. :param decisions: The list of decisions (possibly empty) made by
  286. the decider while processing this decision task. See the docs
  287. for the Decision structure for details.
  288. :type execution_context: string
  289. :param execution_context: User defined context to add to
  290. workflow execution.
  291. :raises: #UnknownResourceFault, #OperationNotPermittedFault
  292. """
  293. data = {'taskToken': task_token}
  294. if decisions:
  295. data['decisions'] = decisions
  296. if execution_context:
  297. data['executionContext'] = execution_context
  298. json_input = json.dumps(data)
  299. return self.make_request('RespondDecisionTaskCompleted', json_input)
  300. def request_cancel_workflow_execution(self, domain, workflow_id,
  301. run_id=None):
  302. """
  303. Records a WorkflowExecutionCancelRequested event in the
  304. currently running workflow execution identified by the given
  305. domain, workflowId, and runId. This logically requests the
  306. cancellation of the workflow execution as a whole. It is up to
  307. the decider to take appropriate actions when it receives an
  308. execution history with this event.
  309. :type domain: string
  310. :param domain: The name of the domain containing the workflow
  311. execution to cancel.
  312. :type run_id: string
  313. :param run_id: The runId of the workflow execution to cancel.
  314. :type workflow_id: string
  315. :param workflow_id: The workflowId of the workflow execution
  316. to cancel.
  317. :raises: UnknownResourceFault, OperationNotPermittedFault
  318. """
  319. data = {'domain': domain, 'workflowId': workflow_id}
  320. if run_id:
  321. data['runId'] = run_id
  322. json_input = json.dumps(data)
  323. return self.make_request('RequestCancelWorkflowExecution', json_input)
  324. def start_workflow_execution(self, domain, workflow_id,
  325. workflow_name, workflow_version,
  326. task_list=None, child_policy=None,
  327. execution_start_to_close_timeout=None,
  328. input=None, tag_list=None,
  329. task_start_to_close_timeout=None):
  330. """
  331. Starts an execution of the workflow type in the specified
  332. domain using the provided workflowId and input data.
  333. :type domain: string
  334. :param domain: The name of the domain in which the workflow
  335. execution is created.
  336. :type workflow_id: string
  337. :param workflow_id: The user defined identifier associated with
  338. the workflow execution. You can use this to associate a
  339. custom identifier with the workflow execution. You may
  340. specify the same identifier if a workflow execution is
  341. logically a restart of a previous execution. You cannot
  342. have two open workflow executions with the same workflowId
  343. at the same time.
  344. :type workflow_name: string
  345. :param workflow_name: The name of the workflow type.
  346. :type workflow_version: string
  347. :param workflow_version: The version of the workflow type.
  348. :type task_list: string
  349. :param task_list: The task list to use for the decision tasks
  350. generated for this workflow execution. This overrides the
  351. defaultTaskList specified when registering the workflow type.
  352. :type child_policy: string
  353. :param child_policy: If set, specifies the policy to use for the
  354. child workflow executions of this workflow execution if it
  355. is terminated, by calling the TerminateWorkflowExecution
  356. action explicitly or due to an expired timeout. This policy
  357. overrides the default child policy specified when registering
  358. the workflow type using RegisterWorkflowType. The supported
  359. child policies are:
  360. * TERMINATE: the child executions will be terminated.
  361. * REQUEST_CANCEL: a request to cancel will be attempted
  362. for each child execution by recording a
  363. WorkflowExecutionCancelRequested event in its history.
  364. It is up to the decider to take appropriate actions
  365. when it receives an execution history with this event.
  366. * ABANDON: no action will be taken. The child executions
  367. will continue to run.
  368. :type execution_start_to_close_timeout: string
  369. :param execution_start_to_close_timeout: The total duration for
  370. this workflow execution. This overrides the
  371. defaultExecutionStartToCloseTimeout specified when
  372. registering the workflow type.
  373. :type input: string
  374. :param input: The input for the workflow
  375. execution. This is a free form string which should be
  376. meaningful to the workflow you are starting. This input is
  377. made available to the new workflow execution in the
  378. WorkflowExecutionStarted history event.
  379. :type tag_list: list :param tag_list: The list of tags to
  380. associate with the workflow execution. You can specify a
  381. maximum of 5 tags. You can list workflow executions with a
  382. specific tag by calling list_open_workflow_executions or
  383. list_closed_workflow_executions and specifying a TagFilter.
  384. :type task_start_to_close_timeout: string :param
  385. task_start_to_close_timeout: Specifies the maximum duration of
  386. decision tasks for this workflow execution. This parameter
  387. overrides the defaultTaskStartToCloseTimout specified when
  388. registering the workflow type using register_workflow_type.
  389. :raises: UnknownResourceFault, TypeDeprecatedFault,
  390. WorkflowExecutionAlreadyStartedFault, LimitExceededFault,
  391. OperationNotPermittedFault, DefaultUndefinedFault
  392. """
  393. data = {'domain': domain, 'workflowId': workflow_id}
  394. data['workflowType'] = {'name': workflow_name,
  395. 'version': workflow_version}
  396. if task_list:
  397. data['taskList'] = {'name': task_list}
  398. if child_policy:
  399. data['childPolicy'] = child_policy
  400. if execution_start_to_close_timeout:
  401. data['executionStartToCloseTimeout'] = execution_start_to_close_timeout
  402. if input:
  403. data['input'] = input
  404. if tag_list:
  405. data['tagList'] = tag_list
  406. if task_start_to_close_timeout:
  407. data['taskStartToCloseTimeout'] = task_start_to_close_timeout
  408. json_input = json.dumps(data)
  409. return self.make_request('StartWorkflowExecution', json_input)
  410. def signal_workflow_execution(self, domain, signal_name, workflow_id,
  411. input=None, run_id=None):
  412. """
  413. Records a WorkflowExecutionSignaled event in the workflow
  414. execution history and creates a decision task for the workflow
  415. execution identified by the given domain, workflowId and
  416. runId. The event is recorded with the specified user defined
  417. signalName and input (if provided).
  418. :type domain: string
  419. :param domain: The name of the domain containing the workflow
  420. execution to signal.
  421. :type signal_name: string
  422. :param signal_name: The name of the signal. This name must be
  423. meaningful to the target workflow.
  424. :type workflow_id: string
  425. :param workflow_id: The workflowId of the workflow execution
  426. to signal.
  427. :type input: string
  428. :param input: Data to attach to the WorkflowExecutionSignaled
  429. event in the target workflow execution's history.
  430. :type run_id: string
  431. :param run_id: The runId of the workflow execution to signal.
  432. :raises: UnknownResourceFault, OperationNotPermittedFault
  433. """
  434. data = {'domain': domain, 'signalName': signal_name,
  435. 'workflowId': workflow_id}
  436. if input:
  437. data['input'] = input
  438. if run_id:
  439. data['runId'] = run_id
  440. json_input = json.dumps(data)
  441. return self.make_request('SignalWorkflowExecution', json_input)
  442. def terminate_workflow_execution(self, domain, workflow_id,
  443. child_policy=None, details=None,
  444. reason=None, run_id=None):
  445. """
  446. Records a WorkflowExecutionTerminated event and forces closure
  447. of the workflow execution identified by the given domain,
  448. runId, and workflowId. The child policy, registered with the
  449. workflow type or specified when starting this execution, is
  450. applied to any open child workflow executions of this workflow
  451. execution.
  452. :type domain: string
  453. :param domain: The domain of the workflow execution to terminate.
  454. :type workflow_id: string
  455. :param workflow_id: The workflowId of the workflow execution
  456. to terminate.
  457. :type child_policy: string
  458. :param child_policy: If set, specifies the policy to use for
  459. the child workflow executions of the workflow execution being
  460. terminated. This policy overrides the child policy specified
  461. for the workflow execution at registration time or when
  462. starting the execution. The supported child policies are:
  463. * TERMINATE: the child executions will be terminated.
  464. * REQUEST_CANCEL: a request to cancel will be attempted
  465. for each child execution by recording a
  466. WorkflowExecutionCancelRequested event in its
  467. history. It is up to the decider to take appropriate
  468. actions when it receives an execution history with this
  469. event.
  470. * ABANDON: no action will be taken. The child executions
  471. will continue to run.
  472. :type details: string
  473. :param details: Optional details for terminating the
  474. workflow execution.
  475. :type reason: string
  476. :param reason: An optional descriptive reason for terminating
  477. the workflow execution.
  478. :type run_id: string
  479. :param run_id: The runId of the workflow execution to terminate.
  480. :raises: UnknownResourceFault, OperationNotPermittedFault
  481. """
  482. data = {'domain': domain, 'workflowId': workflow_id}
  483. if child_policy:
  484. data['childPolicy'] = child_policy
  485. if details:
  486. data['details'] = details
  487. if reason:
  488. data['reason'] = reason
  489. if run_id:
  490. data['runId'] = run_id
  491. json_input = json.dumps(data)
  492. return self.make_request('TerminateWorkflowExecution', json_input)
  493. # Actions related to Administration
  494. ## Activity Management
  495. def register_activity_type(self, domain, name, version, task_list=None,
  496. default_task_heartbeat_timeout=None,
  497. default_task_schedule_to_close_timeout=None,
  498. default_task_schedule_to_start_timeout=None,
  499. default_task_start_to_close_timeout=None,
  500. description=None):
  501. """
  502. Registers a new activity type along with its configuration
  503. settings in the specified domain.
  504. :type domain: string
  505. :param domain: The name of the domain in which this activity is
  506. to be registered.
  507. :type name: string
  508. :param name: The name of the activity type within the domain.
  509. :type version: string
  510. :param version: The version of the activity type.
  511. :type task_list: string
  512. :param task_list: If set, specifies the default task list to
  513. use for scheduling tasks of this activity type. This default
  514. task list is used if a task list is not provided when a task
  515. is scheduled through the schedule_activity_task Decision.
  516. :type default_task_heartbeat_timeout: string
  517. :param default_task_heartbeat_timeout: If set, specifies the
  518. default maximum time before which a worker processing a task
  519. of this type must report progress by calling
  520. RecordActivityTaskHeartbeat. If the timeout is exceeded, the
  521. activity task is automatically timed out. This default can be
  522. overridden when scheduling an activity task using the
  523. ScheduleActivityTask Decision. If the activity worker
  524. subsequently attempts to record a heartbeat or returns a
  525. result, the activity worker receives an UnknownResource
  526. fault. In this case, Amazon SWF no longer considers the
  527. activity task to be valid; the activity worker should clean up
  528. the activity task.no docs
  529. :type default_task_schedule_to_close_timeout: string
  530. :param default_task_schedule_to_close_timeout: If set,
  531. specifies the default maximum duration for a task of this
  532. activity type. This default can be overridden when scheduling
  533. an activity task using the ScheduleActivityTask Decision.no
  534. docs
  535. :type default_task_schedule_to_start_timeout: string
  536. :param default_task_schedule_to_start_timeout: If set,
  537. specifies the default maximum duration that a task of this
  538. activity type can wait before being assigned to a worker. This
  539. default can be overridden when scheduling an activity task
  540. using the ScheduleActivityTask Decision.
  541. :type default_task_start_to_close_timeout: string
  542. :param default_task_start_to_close_timeout: If set, specifies
  543. the default maximum duration that a worker can take to process
  544. tasks of this activity type. This default can be overridden
  545. when scheduling an activity task using the
  546. ScheduleActivityTask Decision.
  547. :type description: string
  548. :param description: A textual description of the activity type.
  549. :raises: TypeAlreadyExistsFault, LimitExceededFault,
  550. UnknownResourceFault, OperationNotPermittedFault
  551. """
  552. data = {'domain': domain, 'name': name,'version': version}
  553. if task_list:
  554. data['taskList'] = {'name': task_list}
  555. if default_task_heartbeat_timeout:
  556. data['defaultTaskHeartbeatTimeout'] = default_task_heartbeat_timeout
  557. if default_task_schedule_to_close_timeout:
  558. data['defaultTaskScheduleToCloseTimeout'] = default_task_schedule_to_close_timeout
  559. if default_task_schedule_to_start_timeout:
  560. data['defaultTaskScheduleToStartTimeout'] = default_task_schedule_to_start_timeout
  561. if default_task_start_to_close_timeout:
  562. data['defaultTaskStartToCloseTimeout'] = default_task_start_to_close_timeout
  563. if description:
  564. data['description'] = description
  565. json_input = json.dumps(data)
  566. return self.make_request('RegisterActivityType', json_input)
  567. def deprecate_activity_type(self, domain, activity_name, activity_version):
  568. """
  569. Returns information about the specified activity type. This
  570. includes configuration settings provided at registration time
  571. as well as other general information about the type.
  572. :type domain: string
  573. :param domain: The name of the domain in which the activity
  574. type is registered.
  575. :type activity_name: string
  576. :param activity_name: The name of this activity.
  577. :type activity_version: string
  578. :param activity_version: The version of this activity.
  579. :raises: UnknownResourceFault, TypeDeprecatedFault,
  580. OperationNotPermittedFault
  581. """
  582. data = {'domain': domain}
  583. data['activityType'] = {'name': activity_name,
  584. 'version': activity_version}
  585. json_input = json.dumps(data)
  586. return self.make_request('DeprecateActivityType', json_input)
  587. ## Workflow Management
  588. def register_workflow_type(self, domain, name, version,
  589. task_list=None,
  590. default_child_policy=None,
  591. default_execution_start_to_close_timeout=None,
  592. default_task_start_to_close_timeout=None,
  593. description=None):
  594. """
  595. Registers a new workflow type and its configuration settings
  596. in the specified domain.
  597. :type domain: string
  598. :param domain: The name of the domain in which to register
  599. the workflow type.
  600. :type name: string
  601. :param name: The name of the workflow type.
  602. :type version: string
  603. :param version: The version of the workflow type.
  604. :type task_list: list of name, version of tasks
  605. :param name: If set, specifies the default task list to use
  606. for scheduling decision tasks for executions of this workflow
  607. type. This default is used only if a task list is not provided
  608. when starting the execution through the StartWorkflowExecution
  609. Action or StartChildWorkflowExecution Decision.
  610. :type default_child_policy: string
  611. :param default_child_policy: If set, specifies the default
  612. policy to use for the child workflow executions when a
  613. workflow execution of this type is terminated, by calling the
  614. TerminateWorkflowExecution action explicitly or due to an
  615. expired timeout. This default can be overridden when starting
  616. a workflow execution using the StartWorkflowExecution action
  617. or the StartChildWorkflowExecution Decision. The supported
  618. child policies are:
  619. * TERMINATE: the child executions will be terminated.
  620. * REQUEST_CANCEL: a request to cancel will be attempted
  621. for each child execution by recording a
  622. WorkflowExecutionCancelRequested event in its
  623. history. It is up to the decider to take appropriate
  624. actions when it receives an execution history with this
  625. event.
  626. * ABANDON: no action will be taken. The child executions
  627. will continue to run.no docs
  628. :type default_execution_start_to_close_timeout: string
  629. :param default_execution_start_to_close_timeout: If set,
  630. specifies the default maximum duration for executions of this
  631. workflow type. You can override this default when starting an
  632. execution through the StartWorkflowExecution Action or
  633. StartChildWorkflowExecution Decision.
  634. :type default_task_start_to_close_timeout: string
  635. :param default_task_start_to_close_timeout: If set, specifies
  636. the default maximum duration of decision tasks for this
  637. workflow type. This default can be overridden when starting a
  638. workflow execution using the StartWorkflowExecution action or
  639. the StartChildWorkflowExecution Decision.
  640. :type description: string
  641. :param description: Textual description of the workflow type.
  642. :raises: TypeAlreadyExistsFault, LimitExceededFault,
  643. UnknownResourceFault, OperationNotPermittedFault
  644. """
  645. data = {'domain': domain, 'name': name, 'version': version}
  646. if task_list:
  647. data['defaultTaskList'] = {'name': task_list}
  648. if default_child_policy:
  649. data['defaultChildPolicy'] = default_child_policy
  650. if default_execution_start_to_close_timeout:
  651. data['defaultExecutionStartToCloseTimeout'] = default_execution_start_to_close_timeout
  652. if default_task_start_to_close_timeout:
  653. data['defaultTaskStartToCloseTimeout'] = default_task_start_to_close_timeout
  654. if description:
  655. data['description'] = description
  656. json_input = json.dumps(data)
  657. return self.make_request('RegisterWorkflowType', json_input)
  658. def deprecate_workflow_type(self, domain, workflow_name, workflow_version):
  659. """
  660. Deprecates the specified workflow type. After a workflow type
  661. has been deprecated, you cannot create new executions of that
  662. type. Executions that were started before the type was
  663. deprecated will continue to run. A deprecated workflow type
  664. may still be used when calling visibility actions.
  665. :type domain: string
  666. :param domain: The name of the domain in which the workflow
  667. type is registered.
  668. :type workflow_name: string
  669. :param workflow_name: The name of the workflow type.
  670. :type workflow_version: string
  671. :param workflow_version: The version of the workflow type.
  672. :raises: UnknownResourceFault, TypeDeprecatedFault,
  673. OperationNotPermittedFault
  674. """
  675. data = {'domain': domain}
  676. data['workflowType'] = {'name': workflow_name,
  677. 'version': workflow_version}
  678. json_input = json.dumps(data)
  679. return self.make_request('DeprecateWorkflowType', json_input)
  680. ## Domain Management
  681. def register_domain(self, name,
  682. workflow_execution_retention_period_in_days,
  683. description=None):
  684. """
  685. Registers a new domain.
  686. :type name: string
  687. :param name: Name of the domain to register. The name must be unique.
  688. :type workflow_execution_retention_period_in_days: string
  689. :param workflow_execution_retention_period_in_days: Specifies
  690. the duration *in days* for which the record (including the
  691. history) of workflow executions in this domain should be kept
  692. by the service. After the retention period, the workflow
  693. execution will not be available in the results of visibility
  694. calls. If a duration of NONE is specified, the records for
  695. workflow executions in this domain are not retained at all.
  696. :type description: string
  697. :param description: Textual description of the domain.
  698. :raises: DomainAlreadyExistsFault, LimitExceededFault,
  699. OperationNotPermittedFault
  700. """
  701. data = {'name': name,
  702. 'workflowExecutionRetentionPeriodInDays': workflow_execution_retention_period_in_days}
  703. if description:
  704. data['description'] = description
  705. json_input = json.dumps(data)
  706. return self.make_request('RegisterDomain', json_input)
  707. def deprecate_domain(self, name):
  708. """
  709. Deprecates the specified domain. After a domain has been
  710. deprecated it cannot be used to create new workflow executions
  711. or register new types. However, you can still use visibility
  712. actions on this domain. Deprecating a domain also deprecates
  713. all activity and workflow types registered in the
  714. domain. Executions that were started before the domain was
  715. deprecated will continue to run.
  716. :type name: string
  717. :param name: The name of the domain to deprecate.
  718. :raises: UnknownResourceFault, DomainDeprecatedFault,
  719. OperationNotPermittedFault
  720. """
  721. data = {'name': name}
  722. json_input = json.dumps(data)
  723. return self.make_request('DeprecateDomain', json_input)
  724. # Visibility Actions
  725. ## Activity Visibility
  726. def list_activity_types(self, domain, registration_status,
  727. name=None,
  728. maximum_page_size=None,
  729. next_page_token=None, reverse_order=None):
  730. """
  731. Returns information about all activities registered in the
  732. specified domain that match the specified name and
  733. registration status. The result includes information like
  734. creation date, current status of the activity, etc. The
  735. results may be split into multiple pages. To retrieve
  736. subsequent pages, make the call again using the nextPageToken
  737. returned by the initial call.
  738. :type domain: string
  739. :param domain: The name of the domain in which the activity
  740. types have been registered.
  741. :type registration_status: string
  742. :param registration_status: Specifies the registration status
  743. of the activity types to list. Valid values are:
  744. * REGISTERED
  745. * DEPRECATED
  746. :type name: string
  747. :param name: If specified, only lists the activity types that
  748. have this name.
  749. :type maximum_page_size: integer
  750. :param maximum_page_size: The maximum number of results
  751. returned in each page. The default is 100, but the caller can
  752. override this value to a page size smaller than the
  753. default. You cannot specify a page size greater than 100.
  754. :type next_page_token: string
  755. :param next_page_token: If on a previous call to this method a
  756. NextResultToken was returned, the results have more than one
  757. page. To get the next page of results, repeat the call with
  758. the nextPageToken and keep all other arguments unchanged.
  759. :type reverse_order: boolean
  760. :param reverse_order: When set to true, returns the results in
  761. reverse order. By default the results are returned in
  762. ascending alphabetical order of the name of the activity
  763. types.
  764. :raises: OperationNotPermittedFault, UnknownResourceFault
  765. """
  766. data = {'domain': domain, 'registrationStatus': registration_status}
  767. if name:
  768. data['name'] = name
  769. if maximum_page_size:
  770. data['maximumPageSize'] = maximum_page_size
  771. if next_page_token:
  772. data['nextPageToken'] = next_page_token
  773. if reverse_order:
  774. data['reverseOrder'] = 'true'
  775. json_input = json.dumps(data)
  776. return self.make_request('ListActivityTypes', json_input)
  777. def describe_activity_type(self, domain, activity_name, activity_version):
  778. """
  779. Returns information about the specified activity type. This
  780. includes configuration settings provided at registration time
  781. as well as other general information about the type.
  782. :type domain: string
  783. :param domain: The name of the domain in which the activity
  784. type is registered.
  785. :type activity_name: string
  786. :param activity_name: The name of this activity.
  787. :type activity_version: string
  788. :param activity_version: The version of this activity.
  789. :raises: UnknownResourceFault, OperationNotPermittedFault
  790. """
  791. data = {'domain': domain}
  792. data['activityType'] = {'name': activity_name,
  793. 'version': activity_version}
  794. json_input = json.dumps(data)
  795. return self.make_request('DescribeActivityType', json_input)
  796. ## Workflow Visibility
  797. def list_workflow_types(self, domain, registration_status,
  798. maximum_page_size=None, name=None,
  799. next_page_token=None, reverse_order=None):
  800. """
  801. Returns information about workflow types in the specified
  802. domain. The results may be split into multiple pages that can
  803. be retrieved by making the call repeatedly.
  804. :type domain: string
  805. :param domain: The name of the domain in which the workflow
  806. types have been registered.
  807. :type registration_status: string
  808. :param registration_status: Specifies the registration status
  809. of the activity types to list. Valid values are:
  810. * REGISTERED
  811. * DEPRECATED
  812. :type name: string
  813. :param name: If specified, lists the workflow type with this name.
  814. :type maximum_page_size: integer
  815. :param maximum_page_size: The maximum number of results
  816. returned in each page. The default is 100, but the caller can
  817. override this value to a page size smaller than the
  818. default. You cannot specify a page size greater than 100.
  819. :type next_page_token: string
  820. :param next_page_token: If on a previous call to this method a
  821. NextPageToken was returned, the results are being
  822. paginated. To get the next page of results, repeat the call
  823. with the returned token and all other arguments unchanged.
  824. :type reverse_order: boolean
  825. :param reverse_order: When set to true, returns the results in
  826. reverse order. By default the results are returned in
  827. ascending alphabetical order of the name of the workflow
  828. types.
  829. :raises: OperationNotPermittedFault, UnknownResourceFault
  830. """
  831. data = {'domain': domain, 'registrationStatus': registration_status}
  832. if maximum_page_size:
  833. data['maximumPageSize'] = maximum_page_size
  834. if name:
  835. data['name'] = name
  836. if next_page_token:
  837. data['nextPageToken'] = next_page_token
  838. if reverse_order:
  839. data['reverseOrder'] = 'true'
  840. json_input = json.dumps(data)
  841. return self.make_request('ListWorkflowTypes', json_input)
  842. def describe_workflow_type(self, domain, workflow_name, workflow_version):
  843. """
  844. Returns information about the specified workflow type. This
  845. includes configuration settings specified when the type was
  846. registered and other information such as creation date,
  847. current status, etc.
  848. :type domain: string
  849. :param domain: The name of the domain in which this workflow
  850. type is registered.
  851. :type workflow_name: string
  852. :param workflow_name: The name of the workflow type.
  853. :type workflow_version: string
  854. :param workflow_version: The version of the workflow type.
  855. :raises: UnknownResourceFault, OperationNotPermittedFault
  856. """
  857. data = {'domain': domain}
  858. data['workflowType'] = {'name': workflow_name,
  859. 'version': workflow_version}
  860. json_input = json.dumps(data)
  861. return self.make_request('DescribeWorkflowType', json_input)
  862. ## Workflow Execution Visibility
  863. def describe_workflow_execution(self, domain, run_id, workflow_id):
  864. """
  865. Returns information about the specified workflow execution
  866. including its type and some statistics.
  867. :type domain: string
  868. :param domain: The name of the domain containing the
  869. workflow execution.
  870. :type run_id: string
  871. :param run_id: A system generated unique identifier for the
  872. workflow execution.
  873. :type workflow_id: string
  874. :param workflow_id: The user defined identifier associated
  875. with the workflow execution.
  876. :raises: UnknownResourceFault, OperationNotPermittedFault
  877. """
  878. data = {'domain': domain}
  879. data['execution'] = {'runId': run_id, 'workflowId': workflow_id}
  880. json_input = json.dumps(data)
  881. return self.make_request('DescribeWorkflowExecution', json_input)
  882. def get_workflow_execution_history(self, domain, run_id, workflow_id,
  883. maximum_page_size=None,
  884. next_page_token=None,
  885. reverse_order=None):
  886. """
  887. Returns the history of the specified workflow execution. The
  888. results may be split into multiple pages. To retrieve
  889. subsequent pages, make the call again using the nextPageToken
  890. returned by the initial call.
  891. :type domain: string
  892. :param domain: The name of the domain containing the
  893. workflow execution.
  894. :type run_id: string
  895. :param run_id: A system generated unique identifier for the
  896. workflow execution.
  897. :type workflow_id: string
  898. :param workflow_id: The user defined identifier associated
  899. with the workflow execution.
  900. :type maximum_page_size: integer
  901. :param maximum_page_size: Specifies the maximum number of
  902. history events returned in one page. The next page in the
  903. result is identified by the NextPageToken returned. By default
  904. 100 history events are returned in a page but the caller can
  905. override this value to a page size smaller than the
  906. default. You cannot specify a page size larger than 100.
  907. :type next_page_token: string
  908. :param next_page_token: If a NextPageToken is returned, the
  909. result has more than one pages. To get the next page, repeat
  910. the call and specify the nextPageToken with all other
  911. arguments unchanged.
  912. :type reverse_order: boolean
  913. :param reverse_order: When set to true, returns the events in
  914. reverse order. By default the results are returned in
  915. ascending order of the eventTimeStamp of the events.
  916. :raises: UnknownResourceFault, OperationNotPermittedFault
  917. """
  918. data = {'domain': domain}
  919. data['execution'] = {'runId': run_id, 'workflowId': workflow_id}
  920. if maximum_page_size:
  921. data['maximumPageSize'] = maximum_page_size
  922. if next_page_token:
  923. data['nextPageToken'] = next_page_token
  924. if reverse_order:
  925. data['reverseOrder'] = 'true'
  926. json_input = json.dumps(data)
  927. return self.make_request('GetWorkflowExecutionHistory', json_input)
  928. def count_open_workflow_executions(self, domain, latest_date, oldest_date,
  929. tag=None, workflow_id=None,
  930. workflow_name=None,
  931. workflow_version=None):
  932. """
  933. Returns the number of open workflow executions within the
  934. given domain that meet the specified filtering criteria.
  935. .. note:
  936. workflow_id, workflow_name/workflow_version and tag are mutually
  937. exclusive. You can specify at most one of these in a request.
  938. :type domain: string
  939. :param domain: The name of the domain containing the
  940. workflow executions to count.
  941. :type latest_date: timestamp
  942. :param latest_date: Specifies the latest start or close date
  943. and time to return.
  944. :type oldest_date: timestamp
  945. :param oldest_date: Specifies the oldest start or close date
  946. and time to return.
  947. :type workflow_name: string
  948. :param workflow_name: Name of the workflow type to filter on.
  949. :type workflow_version: string
  950. :param workflow_version: Version of the workflow type to filter on.
  951. :type tag: string
  952. :param tag: If specified, only executions that have a tag
  953. that matches the filter are counted.
  954. :type workflow_id: string
  955. :param workflow_id: If specified, only workflow executions
  956. matching the workflow_id are counted.
  957. :raises: #UnknownResourceFault, #OperationNotPermittedFault
  958. """
  959. data = {'domain': domain}
  960. data['startTimeFilter'] = {'oldestDate': oldest_date,
  961. 'latestDate': latest_date}
  962. if workflow_name and workflow_version:
  963. data['typeFilter'] = {'name': workflow_name,
  964. 'version': workflow_version}
  965. if workflow_id:
  966. data['executionFilter'] = {'workflowId': workflow_id}
  967. if tag:
  968. data['tagFilter'] = {'tag': tag}
  969. json_input = json.dumps(data)
  970. return self.make_request('CountOpenWorkflowExecutions', json_input)
  971. def list_open_workflow_executions(self, domain,
  972. latest_date=None,
  973. oldest_date=None,
  974. tag=None, workflow_id=None,
  975. workflow_name=None,
  976. workflow_version=None,
  977. maximum_page_size=None,
  978. next_page_token=None,
  979. reverse_order=None):
  980. """
  981. Returns the list of open workflow executions within the
  982. given domain that meet the specified filtering criteria.
  983. .. note:
  984. workflow_id, workflow_name/workflow_version
  985. and tag are mutually exclusive. You can specify at most
  986. one of these in a request.
  987. :type domain: string
  988. :param domain: The name of the domain containing the
  989. workflow executions to count.
  990. :type latest_date: timestamp
  991. :param latest_date: Specifies the latest start or close date
  992. and time to return.
  993. :type oldest_date: timestamp
  994. :param oldest_date: Specifies the oldest start or close date
  995. and time to return.
  996. :type tag: string
  997. :param tag: If specified, only executions that have a tag
  998. that matches the filter are counted.
  999. :type workflow_id: string
  1000. :param workflow_id: If specified, only workflow executions
  1001. matching the workflow_id are counted.
  1002. :type workflow_name: string
  1003. :param workflow_name: Name of the workflow type to filter on.
  1004. :type workflow_version: string
  1005. :param workflow_version: Version of the workflow type to filter on.
  1006. :type maximum_page_size: integer
  1007. :param maximum_page_size: The maximum number of results
  1008. returned in each page. The default is 100, but the caller can
  1009. override this value to a page size smaller than the
  1010. default. You cannot specify a page size greater than 100.
  1011. :type next_page_token: string
  1012. :param next_page_token: If on a previous call to this method a
  1013. NextPageToken was returned, the results are being
  1014. paginated. To get the next page of results, repeat the call
  1015. with the returned token and all other arguments unchanged.
  1016. :type reverse_order: boolean
  1017. :param reverse_order: When set to true, returns the results in
  1018. reverse order. By default the results are returned in
  1019. descending order of the start or the close time of the
  1020. executions.
  1021. :raises: UnknownResourceFault, OperationNotPermittedFault
  1022. """
  1023. data = {'domain': domain}
  1024. data['startTimeFilter'] = {'oldestDate': oldest_date,
  1025. 'latestDate': latest_date}
  1026. if tag:
  1027. data['tagFilter'] = {'tag': tag}
  1028. if workflow_name and workflow_version:
  1029. data['typeFilter'] = {'name': workflow_name,
  1030. 'version': workflow_version}
  1031. if workflow_id:
  1032. data['executionFilter'] = {'workflowId': workflow_id}
  1033. if maximum_page_size:
  1034. data['maximumPageSize'] = maximum_page_size
  1035. if next_page_token:
  1036. data['nextPageToken'] = next_page_token
  1037. if reverse_order:
  1038. data['reverseOrder'] = 'true'
  1039. json_input = json.dumps(data)
  1040. return self.make_request('ListOpenWorkflowExecutions', json_input)
  1041. def count_closed_workflow_executions(self, domain,
  1042. start_latest_date=None,
  1043. start_oldest_date=None,
  1044. close_latest_date=None,
  1045. close_oldest_date=None,
  1046. close_status=None,
  1047. tag=None, workflow_id=None,
  1048. workflow_name=None,
  1049. workflow_version=None):
  1050. """
  1051. Returns the number of closed workflow executions within the
  1052. given domain that meet the specified filtering criteria.
  1053. .. note:
  1054. close_status, workflow_id, workflow_name/workflow_version
  1055. and tag are mutually exclusive. You can specify at most
  1056. one of these in a request.
  1057. .. note:
  1058. start_latest_date/start_oldest_date and
  1059. close_latest_date/close_oldest_date are mutually
  1060. exclusive. You can specify at most one of these in a request.
  1061. :type domain: string
  1062. :param domain: The name of the domain containing the
  1063. workflow executions to count.
  1064. :type start_latest_date: timestamp
  1065. :param start_latest_date: If specified, only workflow executions
  1066. that meet the start time criteria of the filter are counted.
  1067. :type start_oldest_date: timestamp
  1068. :param start_oldest_date: If specified, only workflow executions
  1069. that meet the start time criteria of the filter are counted.
  1070. :type close_latest_date: timestamp
  1071. :param close_latest_date: If specified, only workflow executions
  1072. that meet the close time criteria of the filter are counted.
  1073. :type close_oldest_date: timestamp
  1074. :param close_oldest_date: If specified, only workflow executions
  1075. that meet the close time criteria of the filter are counted.
  1076. :type close_status: string
  1077. :param close_status: The close status that must match the close status
  1078. of an execution for it to meet the criteria of this filter.
  1079. Valid values are:
  1080. * COMPLETED
  1081. * FAILED
  1082. * CANCELED
  1083. * TERMINATED
  1084. * CONTINUED_AS_NEW
  1085. * TIMED_OUT
  1086. :type tag: string
  1087. :param tag: If specified, only executions that have a tag
  1088. that matches the filter are counted.
  1089. :type workflow_id: string
  1090. :param workflow_id: If specified, only workflow executions
  1091. matching the workflow_id are counted.
  1092. :type workflow_name: string
  1093. :param workflow_name: Name of the workflow type to filter on.
  1094. :type workflow_version: string
  1095. :param workflow_version: Version of the workflow type to filter on.
  1096. :raises: UnknownResourceFault, OperationNotPermittedFault
  1097. """
  1098. data = {'domain': domain}
  1099. if start_latest_date and start_oldest_date:
  1100. data['startTimeFilter'] = {'oldestDate': start_oldest_date,
  1101. 'latestDate': start_latest_date}
  1102. if close_latest_date and close_oldest_date:
  1103. data['closeTimeFilter'] = {'oldestDate': close_oldest_date,
  1104. 'latestDate': close_latest_date}
  1105. if close_status:
  1106. data['closeStatusFilter'] = {'status': close_status}
  1107. if tag:
  1108. data['tagFilter'] = {'tag': tag}
  1109. if workflow_name and workflow_version:
  1110. data['typeFilter'] = {'name': workflow_name,
  1111. 'version': workflow_version}
  1112. json_input = json.dumps(data)
  1113. return self.make_request('CountClosedWorkflowExecutions', json_input)
  1114. def list_closed_workflow_executions(self, domain,
  1115. start_latest_date=None,
  1116. start_oldest_date=None,
  1117. close_latest_date=None,
  1118. close_oldest_date=None,
  1119. close_status=None,
  1120. tag=None, workflow_id=None,
  1121. workflow_name=None,
  1122. workflow_version=None,
  1123. maximum_page_size=None,
  1124. next_page_token=None,
  1125. reverse_order=None):
  1126. """
  1127. Returns the number of closed workflow executions within the
  1128. given domain that meet the specified filtering criteria.
  1129. .. note:
  1130. close_status, workflow_id, workflow_name/workflow_version
  1131. and tag are mutually exclusive. You can specify at most
  1132. one of these in a request.
  1133. .. note:
  1134. start_latest_date/start_oldest_date and
  1135. close_latest_date/close_oldest_date are mutually
  1136. exclusive. You can specify at most one of these in a request.
  1137. :type domain: string
  1138. :param domain: The name of the domain containing the
  1139. workflow executions to count.
  1140. :type start_latest_date: timestamp
  1141. :param start_latest_date: If specified, only workflow executions
  1142. that meet the start time criteria of the filter are counted.
  1143. :type start_oldest_date: timestamp
  1144. :param start_oldest_date: If specified, only workflow executions
  1145. that meet the start time criteria of the filter are counted.
  1146. :type close_latest_date: timestamp
  1147. :param close_latest_date: If specified, only workflow executions
  1148. that meet the close time criteria of the filter are counted.
  1149. :type close_oldest_date: timestamp
  1150. :param close_oldest_date: If specified, only workflow executions
  1151. that meet the close time criteria of the filter are counted.
  1152. :type close_status: string
  1153. :param close_status: The close status that must match the close status
  1154. of an execution for it to meet the criteria of this filter.
  1155. Valid values are:
  1156. * COMPLETED
  1157. * FAILED
  1158. * CANCELED
  1159. * TERMINATED
  1160. * CONTINUED_AS_NEW
  1161. * TIMED_OUT
  1162. :type tag: string
  1163. :param tag: If specified, only executions that have a tag
  1164. that matches the filter are counted.
  1165. :type workflow_id: string
  1166. :param workflow_id: If specified, only workflow executions
  1167. matching the workflow_id are counted.
  1168. :type workflow_name: string
  1169. :param workflow_name: Name of the workflow type to filter on.
  1170. :type workflow_version: string
  1171. :param workflow_version: Version of the workflow type to filter on.
  1172. :type maximum_page_size: integer
  1173. :param maximum_page_size: The maximum number of results
  1174. returned in each page. The default is 100, but the caller can
  1175. override this value to a page size smaller than the
  1176. default. You cannot specify a page size greater than 100.
  1177. :type next_page_token: string
  1178. :param next_page_token: If on a previous call to this method a
  1179. NextPageToken was returned, the results are being
  1180. paginated. To get the next page of results, repeat the call
  1181. with the returned token and all other arguments unchanged.
  1182. :type reverse_order: boolean
  1183. :param reverse_order: When set to true, returns the results in
  1184. reverse order. By default the results are returned in
  1185. descending order of the start or the close time of the
  1186. executions.
  1187. :raises: UnknownResourceFault, OperationNotPermittedFault
  1188. """
  1189. data = {'domain': domain}
  1190. if start_latest_date and start_oldest_date:
  1191. data['startTimeFilter'] = {'oldestDate': start_oldest_date,
  1192. 'latestDate': start_latest_date}
  1193. if close_latest_date and close_oldest_date:
  1194. data['closeTimeFilter'] = {'oldestDate': close_oldest_date,
  1195. 'latestDate': close_latest_date}
  1196. if workflow_id:
  1197. data['executionFilter'] = {'workflowId': workflow_id}
  1198. if close_status:
  1199. data['closeStatusFilter'] = {'status': close_status}
  1200. if tag:
  1201. data['tagFilter'] = {'tag': tag}
  1202. if workflow_name and workflow_version:
  1203. data['typeFilter'] = {'name': workflow_name,
  1204. 'version': workflow_version}
  1205. if maximum_page_size:
  1206. data['maximumPageSize'] = maximum_page_size
  1207. if next_page_token:
  1208. data['nextPageToken'] = next_page_token
  1209. if reverse_order:
  1210. data['reverseOrder'] = 'true'
  1211. json_input = json.dumps(data)
  1212. return self.make_request('ListClosedWorkflowExecutions', json_input)
  1213. ## Domain Visibility
  1214. def list_domains(self, registration_status,
  1215. maximum_page_size=None,
  1216. next_page_token=None, reverse_order=None):
  1217. """
  1218. Returns the list of domains registered in the account. The
  1219. results may be split into multiple pages. To retrieve
  1220. subsequent pages, make the call again using the nextPageToken
  1221. returned by the initial call.
  1222. :type registration_status: string
  1223. :param registration_status: Specifies the registration status
  1224. of the domains to list. Valid Values:
  1225. * REGISTERED
  1226. * DEPRECATED
  1227. :type maximum_page_size: integer
  1228. :param maximum_page_size: The maximum number of results
  1229. returned in each page. The default is 100, but the caller can
  1230. override this value to a page size smaller than the
  1231. default. You cannot specify a page size greater than 100.
  1232. :type next_page_token: string
  1233. :param next_page_token: If on a previous call to this method a
  1234. NextPageToken was returned, the result has more than one
  1235. page. To get the next page of results, repeat the call with
  1236. the returned token and all other arguments unchanged.
  1237. :type reverse_order: boolean
  1238. :param reverse_order: When set to true, returns the results in
  1239. reverse order. By default the results are returned in
  1240. ascending alphabetical order of the name of the domains.
  1241. :raises: OperationNotPermittedFault
  1242. """
  1243. data = {'registrationStatus': registration_status}
  1244. if maximum_page_size:
  1245. data['maximumPageSize'] = maximum_page_size
  1246. if next_page_token:
  1247. data['nextPageToken'] = next_page_token
  1248. if reverse_order:
  1249. data['reverseOrder'] = 'true'
  1250. json_input = json.dumps(data)
  1251. return self.make_request('ListDomains', json_input)
  1252. def describe_domain(self, name):
  1253. """
  1254. Returns information about the specified domain including
  1255. description and status.
  1256. :type name: string
  1257. :param name: The name of the domain to describe.
  1258. :raises: UnknownResourceFault, OperationNotPermittedFault
  1259. """
  1260. data = {'name': name}
  1261. json_input = json.dumps(data)
  1262. return self.make_request('DescribeDomain', json_input)
  1263. ## Task List Visibility
  1264. def count_pending_decision_tasks(self, domain, task_list):
  1265. """
  1266. Returns the estimated number of decision tasks in the
  1267. specified task list. The count returned is an approximation
  1268. and is not guaranteed to be exact. If you specify a task list
  1269. that no decision task was ever scheduled in then 0 will be
  1270. returned.
  1271. :type domain: string
  1272. :param domain: The name of the domain that contains the task list.
  1273. :type task_list: string
  1274. :param task_list: The name of the task list.
  1275. :raises: #UnknownResourceFault, #OperationNotPermittedFault
  1276. """
  1277. data = {'domain': domain, 'taskList': {'name': task_list}}
  1278. json_input = json.dumps(data)
  1279. return self.make_request('CountPendingDecisionTasks', json_input)
  1280. def count_pending_activity_tasks(self, domain, task_list):
  1281. """
  1282. Returns the estimated number of activity tasks in the
  1283. specified task list. The count returned is an approximation
  1284. and is not guaranteed to be exact. If you specify a task list
  1285. that no activity task was ever scheduled in then 0 will be
  1286. returned.
  1287. :type domain: string
  1288. :param domain: The name of the domain that contains the task list.
  1289. :type task_list: string
  1290. :param task_list: The name of the task list.
  1291. :raises: UnknownResourceFault, OperationNotPermittedFault
  1292. """
  1293. data = {'domain': domain, 'taskList': {'name': task_list}}
  1294. json_input = json.dumps(data)
  1295. return self.make_request('CountPendingActivityTasks', json_input)