Skip to content
Snippets Groups Projects
Commit 17cfb156 authored by Christoph Alt's avatar Christoph Alt
Browse files

moved function to extract the timestamp from env here

parent 6fd2f46a
Branches
Tags
No related merge requests found
Pipeline #50887 passed with stages
in 24 seconds
import logging
import operator
import os
import time
from datetime import datetime
from functools import reduce
from pathlib import Path
......@@ -71,5 +73,17 @@ def time_conversion(time_stamp, *, pattern="%Y-%m-%d %H:%M:%S"):
return int(dt.timestamp())
def get_time_stamp_from_env(key='CI_PIPELINE_CREATED_AT'):
"""
Try to get the time stamp from the environment and
convert it to an int. If that fails use the current time
"""
try:
return time_conversion(os.environ[key])
except KeyError:
logger.debug(f'Could not find timestamp with ${key}')
return int(time.time())
def get_from_nested_dict(nested_dict, keys):
return reduce(operator.getitem, keys, nested_dict)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment