CREATE OR REPLACE TASK SUNO_PROD.PROD.AGG_USER_DAILY_INSERT
    WAREHOUSE = SUNO_PROD_X_SMAL
    AFTER SUNO_PROD.PROD.AGG_USER_DAILY_SPINE_INSERT
AS 
DECLARE
    p_date VARCHAR;
    row_count NUMBER;
    start_time TIMESTAMP;
BEGIN
    start_time := CURRENT_TIMESTAMP();
    p_date := DATE(SYSDATE() - INTERVAL '1 DAY');
    CALL agg_user_daily_proc(:p_date);  

    SELECT COUNT(*) INTO :row_count
    FROM suno_prod.prod.agg_user_daily
    WHERE p_date = :p_date;
    CALL TASK_MONITOR_INSERT_PROC('AGG_USER_DAILY_INSERT', :start_time, :row_count, 'SUCCESS', 'DAILY');
END;
