Merge branch '19844-paging' refs #19844
[arvados.git] / sdk / cwl / arvados_cwl / util.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import datetime
6 from arvados.errors import ApiError
7
8 collectionUUID =  "http://arvados.org/cwl#collectionUUID"
9
10 def get_intermediate_collection_info(workflow_step_name, current_container, intermediate_output_ttl):
11         if workflow_step_name:
12             name = "Intermediate collection for step %s" % (workflow_step_name)
13         else:
14             name = "Intermediate collection"
15         trash_time = None
16         if intermediate_output_ttl > 0:
17             trash_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=intermediate_output_ttl)
18         container_uuid = None
19         props = {"type": "intermediate"}
20         if current_container:
21             props["container"] = current_container['uuid']
22
23         return {"name" : name, "trash_at" : trash_time, "properties" : props}
24
25 def get_current_container(api, num_retries=0, logger=None):
26     current_container = None
27     try:
28         current_container = api.containers().current().execute(num_retries=num_retries)
29     except ApiError as e:
30         # Status code 404 just means we're not running in a container.
31         if e.resp.status != 404:
32             if logger:
33                 logger.info("Getting current container: %s", e)
34             raise e
35
36     return current_container