logging

{% macro insert_audit(JOB_STATUS) %}
{% if JOB_STATUS == 'In Progress' %}
    insert into {{ target.database }}.LOGGING.PLATFORM_LOGS(PROJECT_NAME,JOB_NAME,JOB_STATUS,JOB_START_TIME,JOB_END_TIME,INVOCATION_ID)
    SELECT '{{ project_name }}',IFF('{{ this }}'='None','{{ project_name }}','{{ this }}'),'{{ JOB_STATUS }}',current_timestamp()::timestamp_ntz,NULL,'{{invocation_id}}';
   
    commit;
{% else %}
    update {{ target.database }}.LOGGING.PLATFORM_LOGS
    set JOB_STATUS='Completed',
        JOB_END_TIME=current_timestamp()::timestamp_ntz
    WHERE INVOCATION_ID='{{invocation_id}}'
    AND JOB_RUN_ID =(select max(JOB_RUN_ID) from {{ target.database }}.LOGGING.PLATFORM_LOGS where JOB_NAME=IFF('{{ this }}'='None','{{ project_name }}','{{ this }}') and JOB_STATUS='In Progress' );

    commit;
{% endif %}

{%- endmacro %}

{% macro results_values(results) %}
  {% for res in results -%}
    {% if loop.index > 1 %},{% endif %}
    '{{ res.status }}'
  {% endfor %}
{% endmacro %}