<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>check_status_job_info_recruits_from_json</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <parameters>
    </parameters>
    <capture_transform_performance>N</capture_transform_performance>
    <transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
    <transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
    <created_user>-</created_user>
    <created_date>2025/06/16 16:12:10.826</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/06/16 16:12:10.826</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Insert / update</from>
      <to>Set variables</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>Set variables</from>
      <to>Write to log</to>
      <enabled>N</enabled>
    </hop>
    <hop>
      <from>Table input</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Insert / update</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>100</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>job_name</field>
        <name>job_name</name>
      </key>
      <schema>public</schema>
      <table>etl_checkpoints</table>
      <value>
        <name>job_name</name>
        <rename>job_name</rename>
        <update>N</update>
      </value>
      <value>
        <name>record_created</name>
        <rename>record_created</rename>
        <update>Y</update>
      </value>
      <value>
        <name>status</name>
        <rename>status</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>1056</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Set variables</name>
    <type>SetVariable</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <fields>
      <field>
        <field_name>job_name</field_name>
        <variable_name>PIPE</variable_name>
        <variable_type>PARENT_WORKFLOW</variable_type>
      </field>
      <field>
        <field_name>status</field_name>
        <variable_name>STATUS</variable_name>
        <variable_type>PARENT_WORKFLOW</variable_type>
      </field>
    </fields>
    <use_formatting>Y</use_formatting>
    <attributes/>
    <GUI>
      <xloc>1296</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table input</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>WITH status_check AS (
    SELECT 
        bool_or(status = 'ERROR' AND job_name IN (
            'job_child', 
            'job_citizen_guardianship',
	     'job_passport',
	     'job_citizen_spouse',
	     'job_prosecution',
            'job_punishment',
            'job_snils_inn',
	     'job_citizen_liability_fz53',
	     'job_citizen_criminal_liability_fz53',
	     'job_citizen_appealing_violations_fz53'
        )) AS has_error,
        count(*) FILTER (
            WHERE status = 'SUCCESS' AND job_name IN (
            'job_child', 
            'job_citizen_guardianship',
	     'job_passport',
	     'job_citizen_spouse',
	     'job_prosecution',
            'job_punishment',
            'job_snils_inn',
	     'job_citizen_liability_fz53',
	     'job_citizen_criminal_liability_fz53',
	     'job_citizen_appealing_violations_fz53'
            )
        ) = 10 AS all_success
    FROM public.etl_checkpoints
)
SELECT 
    'job_info_recruits_from_json' as job_name,
    CASE 
        WHEN has_error THEN 'ERROR'
        WHEN all_success THEN 'SUCCESS'
        ELSE 'ERROR'
    END AS status,
    current_timestamp AS record_created
FROM status_check;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>688</xloc>
      <yloc>384</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Write to log</name>
    <type>WriteToLog</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <displayHeader>Y</displayHeader>
    <fields>
</fields>
    <limitRows>N</limitRows>
    <limitRowsNumber>0</limitRowsNumber>
    <loglevel>Basic</loglevel>
    <logmessage>${STATUS}</logmessage>
    <attributes/>
    <GUI>
      <xloc>1552</xloc>
      <yloc>256</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
