aonestar
.public
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
sp_daily_clear_all_intf_state
Parameters
Name
Type
Mode
Definition
DECLARE v_property RECORD; -- Avail ไม่ต้องการ clear state เพราะใช้ sync_stamp ตรวจสอบ last_sync v_interface_codes text[] := ARRAY['NBIS_CHANNEX_RATE', 'NBIS_CHANNEX_RESTRICTIONS']; v_interface_code text; v_cleared_count int := 0; v_error_count int := 0; BEGIN RAISE NOTICE 'Starting daily clear of all interface state at %', now(); -- Loop ผ่านทุก property ที่ enabled FOR v_property IN SELECT id, code, name FROM property WHERE enabled = true LOOP RAISE NOTICE 'Processing property: % (%)', v_property.name, v_property.code; -- Loop ผ่านทุก interface code FOREACH v_interface_code IN ARRAY v_interface_codes LOOP BEGIN -- Clear state สำหรับ interface นี้ CALL public.sp_clear_intf_rate_state(v_interface_code, v_property.id); v_cleared_count := v_cleared_count + 1; EXCEPTION WHEN OTHERS THEN v_error_count := v_error_count + 1; RAISE WARNING 'Failed to clear % for property %: %', v_interface_code, v_property.code, SQLERRM; END; END LOOP; END LOOP; RAISE NOTICE 'Daily clear completed at %', now(); RAISE NOTICE 'Cleared: % interfaces, Errors: %', v_cleared_count, v_error_count; -- แจ้งเตือนผลการดำเนินการ PERFORM public.sp_system_notify( 'DAILY CLEAR INTERFACE STATE', format( 'Clear completed successfully | Cleared: %s interfaces | Errors: %s', v_cleared_count, v_error_count ), NULL, '🧹' ); END;