create or replace task APP_EVENT_METADATA_DAILY_UPSERT
	warehouse=SUNO_PROD_MOBILE_DAILY_X_SMALL
	schedule='USING CRON 0 1 * * * UTC'
	as declare
        start_time TIMESTAMP;
    begin
        start_time := CURRENT_TIMESTAMP();
        merge into app_event_metadata as target
        using 
        (
            select 
                action_name,
                source
            from app_event
            where p_date = DATE(SYSDATE() - INTERVAL '1 DAY')
            group by 1, 2
        ) as source
        on (target.action_name = source.action_name and target.source = source.source)
        when not matched then
            insert (action_name, source, description)
            values (source.action_name, source.source, '');
        
        call TASK_MONITOR_INSERT_PROC('APP_EVENT_METADATA_DAILY_UPSERT', :start_time, 1, 'SUCCESS', 'DAILY');
    end;