Skip to content
This guide is for Background Jobs Mode. Main docs are here

Configuration

You can pass an optional configuration object as the second argument to EdgeWorker.start() to tweak the worker’s behavior.

EdgeWorker.start(handler, {
// name of the queue to poll for messages
queueName: 'tasks',
// how many tasks are processed at the same time
maxConcurrent: 10,
// how many connections to the database are opened
maxPgConnections: 4,
// in-worker polling interval
maxPollSeconds: 5,
// in-database polling interval
pollIntervalMs: 200,
// retry configuration for failed messages
retry: {
strategy: 'exponential', // exponential backoff (default)
limit: 5, // max retry attempts
baseDelay: 3, // initial delay in seconds
maxDelay: 300, // max delay cap in seconds
},
// how long a job is invisible after reading
// if not successful, will reappear after this time
visibilityTimeout: 10,
});

Type: string Default: 'tasks'

The name of the PGMQ queue to listen to for messages.

EdgeWorker.start(handler, {
queueName: 'my_custom_queue'
});

Type: number Default: 10

The duration (in seconds) that a message remains invisible to other consumers while being processed.

EdgeWorker.start(handler, {
visibilityTimeout: 5 // message will re-appear in queue after 5 seconds if not processed
});

Type: number Default: 10

This option limits concurrency - the maximum number of messages that can be processed at the same time. Increase for IO-heavy tasks (network or db calls), decrease for CPU-heavy tasks.

EdgeWorker.start(handler, {
maxConcurrent: 10 // Process up to 10 messages at once
});

Type: number Default: 4

Maximum number of concurrent database connections. Increase for IO-heavy tasks (network or database operations), decrease for CPU-heavy tasks.

EdgeWorker.start(handler, {
maxPgConnections: 10 // Use up to 10 connections to the database
});

Type: number Default: 5

Amount of seconds to wait for a message to be available in the queue.

EdgeWorker.start(handler, {
maxPollSeconds: 5 // Long-poll for 5 seconds waiting for a message
});

Type: number Default: 200

The interval (in milliseconds) between database polling attempts by pgmq.read_with_poll. The default value is suitable for most use cases.

EdgeWorker.start(handler, {
pollIntervalMs: 300 // Poll every 300ms
});

Type: RetryConfig Default: { strategy: 'exponential', limit: 5, baseDelay: 3, maxDelay: 300 }

Configures how failed messages are retried. Edge Worker supports two retry strategies:

  • exponential (default): Delay doubles with each retry attempt
  • fixed: Constant delay between all retry attempts

Here’s how retry delays differ between strategies with the same base delay:

AttemptFixed (baseDelay: 5s)Exponential (baseDelay: 5s)Exponential (baseDelay: 5s, maxDelay: 60s)
15s5s5s
25s10s10s
35s20s20s
45s40s40s
55s80s60s (capped)
65s160s60s (capped)
75s320s60s (capped)
85s640s60s (capped)

Type:

interface ExponentialRetryConfig {
strategy: 'exponential';
limit: number; // Max retry attempts
baseDelay: number; // Initial delay in seconds
maxDelay?: number; // Maximum delay cap in seconds (default: 300)
}

With exponential backoff, the delay between retries increases exponentially: baseDelay * 2^(attempt-1). For example, with baseDelay: 3, the delays would be 3s, 6s, 12s, 24s, etc.

EdgeWorker.start(handler, {
retry: {
strategy: 'exponential',
limit: 5, // max 5 retry attempts
baseDelay: 2, // start with 2 second delay
maxDelay: 60, // cap delays at 60 seconds
}
});

Type:

interface FixedRetryConfig {
strategy: 'fixed';
limit: number; // Max retry attempts
baseDelay: number; // Constant delay between retries in seconds
}

With fixed delay, the time between retries remains constant regardless of the attempt number.

EdgeWorker.start(handler, {
retry: {
strategy: 'fixed',
limit: 3, // max 3 retry attempts
baseDelay: 10, // always wait 10 seconds between retries
}
});

To disable retries entirely, set limit to 0:

EdgeWorker.start(handler, {
retry: {
strategy: 'fixed', // Strategy doesn't matter when limit is 0
limit: 0, // no retries
baseDelay: 0,
}
});

Type: number Default: 5

Number of seconds to wait between retry attempts when using a fixed delay strategy.

Type: number Default: 5

Maximum number of retry attempts for failed message processing before marking the message as dead.

Your handler functions can access the resolved worker configuration through the context object. For detailed information about available configuration options and usage patterns, see workerConfig.

  • Update pgflow - Keep your pgflow installation up to date with the latest features and bug fixes