{% macro insert_A_TASK_HISTORY(a_workflow_history_key, model_name) %}
{% if execute %}

    {% set insert_A_TASK_HISTORY %}
        INSERT INTO {{ source('control_tables', 'A_TASK_HISTORY') }} (A_TASK_HISTORY_KEY, A_WORKFLOW_HISTORY_KEY, TASK_RUN_ID, TASK_NAME, TASK_START, TASK_SUCCESSFUL, SERVICE_NAME)
        VALUES ({{ source('control_sequences','A_TASK_HISTORY_SEQ') }}.NEXTVAL, {{ a_workflow_history_key }}, '{{ invocation_id}}' ,'{{ model_name }}', cast(current_timestamp as timestamp(0)), 'N', '{{ var("input_service_name") }}')
    {% endset %} 

    {% do run_query(insert_A_TASK_HISTORY) %}

{% endif %}
{% endmacro %}