Skip to content

Create your first worker

Setting up your first worker is straightforward and takes just a few minutes.

  1. Create your worker

    First, create a new Edge Function using the Supabase CLI. Then, replace its content with this code:

    import { EdgeWorker } from "@pgflow/edge-worker";
    EdgeWorker.start(async (payload: { urlToScrape: string }) => {
    // do something with the message
    console.log('Scraping URL...', payload.urlToScrape);
    });
  2. Start Edge Runtime

    Start the Edge Runtime by running the following command:

    npx supabase functions serve
  3. Start your worker

    Start the worker by sending an HTTP request to your Edge Function:

    curl http://localhost:54321/functions/v1/<function-name>
  4. Process your first message

    By default, the worker looks for messages in the tasks queue (this name is configurable).

    Send a test message to the queue:

    SELECT pgmq.send(
    queue_name => 'tasks',
    msg => '{"urlToScrape": "https://example.com"}'::jsonb
    );

    The worker will process the message immediately.