def purge_execution_output_objects(logger, timestamp, action_ref=None):
    """
    Purge action executions output objects.

    :param timestamp: Objects older than this timestamp will be deleted.
    :type timestamp: ``datetime.datetime

    :param action_ref: Only delete objects for the provided actions.
    :type action_ref: ``str``
    """
    if not timestamp:
        raise ValueError("Specify a valid timestamp to purge.")

    logger.info(
        "Purging action execution output objects older than timestamp: %s"
        % timestamp.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
    )

    filters = {}
    filters["timestamp__lt"] = timestamp

    if action_ref:
        filters["action_ref"] = action_ref

    try:
        deleted_count = ActionExecutionOutput.delete_by_query(**filters)
    except InvalidQueryError as e:
        msg = (
            "Bad query (%s) used to delete execution output instances: %s"
            "Please contact support." % (filters, six.text_type(e))
        )
        raise InvalidQueryError(msg)
    except:
        logger.exception(
            "Deletion of execution output models failed for query with filters: %s.",
            filters,
        )
    else:
        logger.info("Deleted %s execution output objects" % (deleted_count))

    Purge action executions output objects.

    :param timestamp: Objects older than this timestamp will be deleted.
    :type timestamp: ``datetime.datetime

    :param action_ref: Only delete objects for the provided actions.
    :type action_ref: ``str``
    
st2common/st2common/garbage_collection/executions.py