{% macro get_task_history_key(model_name) %}
{% if execute %}

    {% set fetch_fk %}
        SELECT A_TASK_HISTORY_KEY 
        FROM {{ source('control_tables', 'A_TASK_HISTORY') }}
        WHERE TASK_RUN_ID = '{{ invocation_id }}'
        AND TASK_NAME = '{{ model_name }}'
        AND SERVICE_NAME = '{{ var("input_service_name") }}'
    {% endset %}

    {% set a_task_history_key_result = run_query(fetch_fk) %}
    {% set a_task_history_key = a_task_history_key_result.columns[0].values()[0] %}

    {{ return(a_task_history_key) }}

{% endif %}
{% endmacro %}


