def copy_and_modify_action()

in elastic/shared/parameter_sources/workflow_selector.py [0:0]


    def copy_and_modify_action(self, action):
        action_id = action["id"]
        if self._max_date:
            query_max_date = self._max_date
        else:
            # process fields - use the start_date + the time passed since we started, as the time
            # all dates for the action should be the same
            query_max_date = self._max_date_start + (self._utc_now().replace(tzinfo=timezone.utc) - self._init_date)

        for query_handler in self.workflow_handlers[action_id]:
            # scale the duration based on the max if set
            duration = None
            query_handler_interval = query_handler.get_time_interval()
            if query_handler_interval and self.max_query_duration:
                duration = ceil(
                    self.max_query_duration * (query_handler_interval.total_seconds() / self._max_time_interval.total_seconds())
                )
                if duration < self._min_query_duration:
                    duration = self._min_query_duration
                duration = timedelta(seconds=duration)
                self.logger.info(
                    "Using duration of [%s]s for workflow [%s] and action [%s]",
                    duration.total_seconds(),
                    self.workflow,
                    action_id,
                )

            date_data = DateTimeValues(min_date=self._min_date, max_date=query_max_date, duration=duration)
            # this modifies these changes by ref - not thread safe
            query_handler.process(date_data)
        # always clone the dictionary as we dont' have guarantees of order in rally - deepcopy
        return deepcopy(action)