- Workers now use PostgreSQL LISTEN/NOTIFY to wake up immediately when proxies are added - Added trigger on proxies table to NOTIFY 'proxy_added' when active proxy inserted/updated - Falls back to 30s polling if LISTEN fails 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
28 lines
938 B
PL/PgSQL
28 lines
938 B
PL/PgSQL
-- Migration: 082_proxy_notification_trigger
|
|
-- Date: 2024-12-11
|
|
-- Description: Add PostgreSQL NOTIFY trigger to alert workers when proxies are added
|
|
|
|
-- Create function to notify workers when active proxy is added/activated
|
|
CREATE OR REPLACE FUNCTION notify_proxy_added()
|
|
RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
-- Only notify if proxy is active
|
|
IF NEW.active = true THEN
|
|
PERFORM pg_notify('proxy_added', NEW.id::text);
|
|
END IF;
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
-- Drop existing trigger if any
|
|
DROP TRIGGER IF EXISTS proxy_added_trigger ON proxies;
|
|
|
|
-- Create trigger on insert and update of active column
|
|
CREATE TRIGGER proxy_added_trigger
|
|
AFTER INSERT OR UPDATE OF active ON proxies
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION notify_proxy_added();
|
|
|
|
COMMENT ON FUNCTION notify_proxy_added() IS
|
|
'Sends PostgreSQL NOTIFY to proxy_added channel when an active proxy is added or activated. Workers LISTEN on this channel to wake up immediately.';
|