### Listen to Events with runner.events Source: https://github.com/graphile/worker/blob/main/examples/readme/README.md Example of listening to events using `runner.events`. This snippet combines quickstart library setup with event listening functionality. ```javascript import { makeWorkerUtils, run } from "@graphile/worker"; import { Pool } from "pg"; // Example: listening to an event with runner.events const pool = new Pool({ connectionString: "postgres://user:password@host:port/database", }); const workerUtils = await makeWorkerUtils({ pool }); const runner = await run({ ...workerUtils, // Listen to events events: { async "job:completed"(payload) { console.log("Job completed:", payload); }, async "job:failed"(payload) { console.error("Job failed:", payload); }, }, }); // Example: adding a job await workerUtils.addJob("my_task", { foo: "bar" }); // Keep the process alive until interrupted process.on("SIGINT", async () => { await runner.stop(); await pool.end(); process.exit(0); }); ``` -------------------------------- ### PostgreSQL Connection String Examples Source: https://github.com/graphile/worker/blob/main/website/docs/cli/run.md Examples of valid PostgreSQL connection strings, demonstrating different levels of detail. ```text postgres:///my_db ``` ```text postgres://127.0.0.1/my_db ``` ```text postgres://127.0.0.1:5432/my_db ``` ```text postgres://postgres:postgres@127.0.0.1:5432/my_db ``` ```text postgres://postgres:postgres@127.0.0.1:5432/my_db?ssl=1 ``` -------------------------------- ### Install Dependencies Source: https://github.com/graphile/worker/blob/main/website/README.md Run this command in the root folder of the repository to install project dependencies. ```bash yarn ``` -------------------------------- ### Install PostgreSQL Client Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Install the PostgreSQL client tools, which are required for setting up test fixtures. This command is for Debian-based systems. ```bash sudo apt update && sudo apt install postgresql-client ``` -------------------------------- ### Start Local Development Server Source: https://github.com/graphile/worker/blob/main/website/README.md Starts a local development server for the website. Changes are reflected live without a server restart. ```bash yarn website start ``` -------------------------------- ### Install Node Dependencies Source: https://github.com/graphile/worker/blob/main/examples/worker-faktory-exporter/README.md Install the necessary Node.js packages for Faktory worker integration. ```bash yarn add faktory-worker yarn add graphile-worker ``` -------------------------------- ### Schemaless Connection String Examples Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md Schemaless connection strings are not recommended. Examples include just the database name or a socket path. ```plaintext dbname ``` ```plaintext /path/to/socket ``` -------------------------------- ### Start Postgres Instance Source: https://github.com/graphile/worker/blob/main/examples/worker-faktory-exporter/README.md Run a PostgreSQL instance using Docker for the worker to connect to. ```bash docker run -it --rm -p 5432:5432 -d postgres:10-alpine ``` -------------------------------- ### Configure and Start Graphile-Worker Source: https://github.com/graphile/worker/blob/main/examples/worker-faktory-exporter/README.md Set environment variables for the database connection and Faktory URL, then start the Graphile-Worker using yarn bin. ```bash export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres export FAKTORY_URL=tcp://:faktorypass@localhost:7419 $(yarn bin)/graphile-worker ``` -------------------------------- ### Install Graphile Worker Pro Source: https://github.com/graphile/worker/blob/main/website/docs/pro/index.md Install the @graphile-pro/worker package using npm after configuring GitHub Packages authentication. ```bash npm install --save @graphile-pro/worker ``` -------------------------------- ### Start Faktory Instance Source: https://github.com/graphile/worker/blob/main/examples/worker-faktory-exporter/README.md Launch a Faktory work server instance using Docker, configuring ports and password. ```bash docker run --rm -it -v faktory-data:/var/lib/faktory -e "FAKTORY_PASSWORD=faktorypass" -p 127.0.0.1:7419:7419 -p 127.0.0.1:7420:7420 contribsys/faktory:latest /faktory -b :7419 -w :7420 -e production ``` -------------------------------- ### Database Schema Installation Source: https://github.com/graphile/worker/blob/main/website/docs/library/queue.md Before queuing jobs, ensure the graphile-worker database schema is installed. This can be done via the CLI or the `WorkerUtils.migrate()` method. ```APIDOC ## Database Schema Installation ### CLI Command ```bash yarn graphile-worker -c "postgres:///my_db" --schema-only ``` ### Programmatic Migration ```javascript import { makeWorkerUtils } from "graphile-worker"; async function migrateSchema() { const workerUtils = await makeWorkerUtils({ connectionString: "postgres:///my_db", }); try { await workerUtils.migrate(); } finally { await workerUtils.release(); } } ``` ``` -------------------------------- ### Postgres Connection String Examples Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md Illustrates different ways to specify a database connection string using the postgres protocol. ```plaintext postgres:///dbname?... ``` ```plaintext postgres:///dbname?host=/path/to/socket&... ``` ```plaintext postgres://user:password@host:port/dbname?... ``` -------------------------------- ### Run Graphile Worker in Library Mode Source: https://github.com/graphile/worker/blob/main/website/docs/library/index.md Configure and start the Graphile Worker within your Node.js application. Ensure graceful shutdown handling by awaiting the runner's promise. This setup is equivalent to the CLI quickstart. ```javascript const { run } = require("graphile-worker"); async function main() { // Run a worker to execute jobs: const runner = await run({ connectionString: "postgres:///my_db", concurrency: 5, // Install signal handlers for graceful shutdown on SIGINT, SIGTERM, etc noHandleSignals: false, pollInterval: 1000, // you can set the taskList or taskDirectory but not both taskList: { hello: async (payload, helpers) => { const { name } = payload; helpers.logger.info(`Hello, ${name}`); }, }, // or: // taskDirectory: `${__dirname}/tasks`, }); // Immediately await (or otherwise handle) the resulting promise, to avoid // "unhandled rejection" errors causing a process crash in the event of // something going wrong. await runner.promise; // If the worker exits (whether through fatal error or otherwise), the above // promise will resolve/reject. } main().catch((err) => { console.error(err); process.exit(1); }); ``` -------------------------------- ### Install Graphile Worker Schema Source: https://github.com/graphile/worker/blob/main/website/docs/library/queue.md Installs the graphile-worker database schema using the CLI. Ensure the database connection string is correct. ```bash yarn graphile-worker -c "postgres:///my_db" --schema-only ``` -------------------------------- ### Domain Socket Connection Example Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md Specifying a connection to a Unix domain socket via a query parameter. ```plaintext postgres:///dbname?host=/path/to/socket ``` ```plaintext postgres://user:pass@/dbname?host=/path/to/socket ``` -------------------------------- ### Socket Protocol Examples Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md Use the `socket:` protocol for connecting to Unix domain sockets. Provide username and password via `@` syntax if needed, but do not specify a host. ```plaintext socket:/path/to/socket?db=dbname&... ``` ```plaintext socket://user:password@/path/to/socket?db=dbname&... ``` -------------------------------- ### Run Graphile Worker with Docker Source: https://github.com/graphile/worker/blob/main/website/docs/docker.md This example shows how to run the Graphile Worker Docker container, mounting a local 'tasks' directory and connecting to a PostgreSQL database. ```bash docker run \ --init \ --rm -it \ --network=host \ -v "$PWD/tasks":/worker/tasks \ graphile/worker \ -c "postgres://postgres:postgres@localhost:5432/postgres" ``` -------------------------------- ### Run Docker Compose Services Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Command to start the Docker containers (db and app) in detached mode. This sets up the development environment. ```shell docker compose up -d ``` -------------------------------- ### Example: Sending Email with Assumed Type Source: https://github.com/graphile/worker/blob/main/website/docs/typescript.md This example demonstrates defining a `send_email` task with its payload type specified globally. It includes necessary imports and the task implementation for sending an email via Amazon SES. ```typescript import type { Task, WorkerUtils } from "graphile-worker"; import { ses } from "./aws"; declare global { namespace GraphileWorker { interface Tasks { send_email: { to: string; subject: string; body: string; }; } } } export const send_email: Task<"send_email"> = async function (payload) { const { to, subject, body } = payload; await ses.sendEmail({ Destination: { ToAddresses: [to], FromAddresses: ["no-reply@example.com"], }, Message: { Subject: { Charset: "UTF-8", Data: subject, }, Body: { Text: { Charset: "UTF-8", Data: body, }, }, }, }); }; ``` -------------------------------- ### Run Temporary PostgreSQL Instance Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Use Docker to run a temporary PostgreSQL instance on port 6432. Ensure you have Docker installed. ```bash # Run a temporary postgres instance on port 6432 docker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=trust -p 6432:5432 postgres:17 ``` -------------------------------- ### Install Node Dependencies for Graphile Worker and Cloud Tasks Source: https://github.com/graphile/worker/blob/main/examples/worker-cloud-tasks-exporter/README.md Add the necessary libraries to your project using yarn or npm. ```bash yarn add @google-cloud/tasks yarn add graphile-worker ``` ```bash npm i @google-cloud/tasks npm i graphile-worker ``` -------------------------------- ### Running Graphile Worker with Configuration File Source: https://github.com/graphile/worker/blob/main/website/docs/config.md Example of an `index.ts` file that imports and uses a Graphile Worker configuration preset to run the worker. ```typescript import { run } from "graphile-worker"; import preset from "./graphile.config"; async function main() { const runner = await run({ preset }); await runner.promise; } main().catch((err) => { console.error(err); process.exit(1); }); ``` -------------------------------- ### Graphile Worker CLI with Socket Connection Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md Example of using a socket connection string with the Graphile Worker CLI. ```bash graphile-worker -c "socket://username:password@/cloudsql/project:region:instance?db=dbname" ``` -------------------------------- ### Example Worker Output Source: https://github.com/graphile/worker/blob/main/website/docs/library/index.md This output demonstrates the typical logs seen when a worker processes a job, including connection messages, task execution, and completion status. ```text [core] INFO: Worker connected and looking for jobs... (task names: 'hello') [job(worker-7327280603017288: hello{1})] INFO: Hello, Bobby Tables [worker(worker-7327280603017288)] INFO: Completed task 1 (hello) with success (0.16ms) ``` -------------------------------- ### Example Trigger Configurations for Dynamic Function Source: https://github.com/graphile/worker/blob/main/website/docs/sql-add-job.md Illustrates how to attach the `trigger_job` function to different tables and events. Each trigger specifies the job identifier to be used by the `add_job` function. ```sql CREATE TRIGGER send_verification_email AFTER INSERT ON user_emails FOR EACH ROW WHEN (NEW.verified is false) EXECUTE PROCEDURE trigger_job('send_verification_email'); ``` ```sql CREATE TRIGGER user_changed AFTER INSERT OR UPDATE OR DELETE ON users FOR EACH ROW EXECUTE PROCEDURE trigger_job('user_changed'); ``` ```sql CREATE TRIGGER generate_pdf AFTER INSERT ON pdfs FOR EACH ROW EXECUTE PROCEDURE trigger_job('generate_pdf'); ``` ```sql CREATE TRIGGER generate_pdf_update AFTER UPDATE ON pdfs FOR EACH ROW WHEN (NEW.title IS DISTINCT FROM OLD.title) EXECUTE PROCEDURE trigger_job('generate_pdf'); ``` -------------------------------- ### Uninstalling pgcrypto Extension Source: https://github.com/graphile/worker/blob/main/RELEASE_NOTES.md If you have a pre-existing installation and wish to uninstall the 'pgcrypto' database extension, run this command after updating to the latest schema. ```sql DROP EXTENSION pgcrypto; ``` -------------------------------- ### Install Graphile Worker Source: https://github.com/graphile/worker/blob/main/website/docs/cli/index.md Add the graphile-worker package to your Node.js project using npm or yarn. ```sh npm install --save graphile-worker ``` -------------------------------- ### Run Graphile Worker with Cloud Tasks Configuration Source: https://github.com/graphile/worker/blob/main/examples/worker-cloud-tasks-exporter/README.md Set environment variables for GCP Cloud Tasks and the database connection, then start the Graphile Worker. ```bash export GOOGLE_CLOUD_TASKS_PROJECT=your-project export GOOGLE_CLOUD_TASKS_LOCATION=your-location export GOOGLE_CLOUD_TASKS_QUEUE=your-queue export DATABASE_URL=your-url $(yarn bin)/graphile-worker ``` -------------------------------- ### Graphile Worker Configuration File Source: https://github.com/graphile/worker/blob/main/website/docs/config.md Example of a `graphile.config.ts` file defining a preset that extends the default WorkerPreset and specifies task directory and database connection string. ```typescript import { WorkerPreset } from "graphile-worker"; const preset: GraphileConfig.Preset = { extends: [WorkerPreset], worker: { taskDirectory: `${__dirname}/tasks`, connectionString: "postgres:///my_db", }, }; export default preset; ``` -------------------------------- ### Custom Logger Implementation Source: https://github.com/graphile/worker/blob/main/website/docs/library/logger.md Implement a custom log factory to control where log messages are sent. This example logs to the console with scope and metadata. ```javascript const { Logger, run } = require("graphile-worker"); /* Replace this function with your own implementation */ function logFactory(scope) { return (level, message, meta) => { console.log(level, message, scope, meta); }; } const logger = new Logger(logFactory); // Pass the logger to the 'run' method as part of options: run({ logger, /* pgPool, taskList, etc... */ }); ``` -------------------------------- ### Add a job with named parameters Source: https://github.com/graphile/worker/blob/main/website/docs/sql-add-job.md Utilize PostgreSQL's named parameters for clarity and to specify only the arguments you need. This example schedules a 'reminder' job to run in two days. ```sql SELECT graphile_worker.add_job('reminder', run_at := NOW() + INTERVAL '2 days'); ``` -------------------------------- ### Get Help for Graphile Worker CLI Source: https://github.com/graphile/worker/blob/main/website/docs/docker.md Run this command within a Docker container to view the available command-line options for Graphile Worker. ```bash docker run --init --rm -it graphile/worker --help ``` -------------------------------- ### Graphile Worker Pro Configuration Example Source: https://github.com/graphile/worker/blob/main/website/docs/pro/config.md Configure Worker Pro options like heartbeatInterval, sweepInterval, sweepThreshold, and maxMigrationWaitTime in your `graphile.config.ts` file. Ensure these values are appropriate for your expected job execution times and network stability. ```typescript import "graphile-config"; import "graphile-worker"; import { WorkerProPreset } from "@graphile-pro/worker"; const preset: GraphileConfig.Preset = { extends: [WorkerProPreset], worker: { /* ... regular configuration here ...*/ /* Example Worker Pro configuration options: */ // Check in as active once per minute heartbeatInterval: 60 * 1000, // Check for and force-release inactive workers every 3 minutes sweepInterval: 3 * 60 * 1000, // Workers are deemed "inactive" 10 minutes after their last heartbeat sweepThreshold: 10 * 60 * 1000, // If old workers haven't exited within 30 minutes, go ahead and perform // the migration anyway: maxMigrationWaitTime: 30 * 60 * 1000, }, }; export default preset; ``` -------------------------------- ### Add Multiple Jobs with addJobs() Source: https://github.com/graphile/worker/blob/main/website/docs/library/add-jobs.md Use this method to add a batch of jobs to the queue. Each job can have an identifier and a payload. This example adds four 'send_email' jobs. ```javascript await addJobs([ { identifier: "send_email", payload: { to: "someone@example.com" } }, { identifier: "send_email", payload: { to: "anyone@example.com" } }, { identifier: "send_email", payload: { to: "thisone@example.com" } }, { identifier: "send_email", payload: { to: "anotherone@example.com" } }, ]); ``` -------------------------------- ### Dynamic Trigger Function Example Source: https://github.com/graphile/worker/blob/main/website/docs/sql-add-job.md An example of a dynamic trigger function that can be used with multiple tables to schedule jobs in Graphile Worker. ```APIDOC ## Dynamic Trigger Function This SQL function `trigger_job` can be used to schedule jobs in Graphile Worker from database triggers. It's designed to be flexible and work with multiple tables that have a primary key named `id`. ### SQL Function Definition ```sql CREATE FUNCTION trigger_job() RETURNS trigger AS $$ BEGIN PERFORM graphile_worker.add_job(TG_ARGV[0], json_build_object( 'schema', TG_TABLE_SCHEMA, 'table', TG_TABLE_NAME, 'op', TG_OP, 'id', (CASE WHEN TG_OP = 'DELETE' THEN OLD.id ELSE NEW.id END) )); RETURN NEW; END; $$ LANGUAGE plpgsql VOLATILE; ``` ### Example Trigger Usage These examples show how to create triggers that utilize the `trigger_job` function. ```sql -- Trigger for sending verification emails after inserting into user_emails CREATE TRIGGER send_verification_email AFTER INSERT ON user_emails FOR EACH ROW WHEN (NEW.verified is false) EXECUTE PROCEDURE trigger_job('send_verification_email'); -- Trigger for handling inserts, updates, or deletes on the users table CREATE TRIGGER user_changed AFTER INSERT OR UPDATE OR DELETE ON users FOR EACH ROW EXECUTE PROCEDURE trigger_job('user_changed'); -- Trigger for generating a PDF after inserting into the pdfs table CREATE TRIGGER generate_pdf AFTER INSERT ON pdfs FOR EACH ROW EXECUTE PROCEDURE trigger_job('generate_pdf'); -- Trigger for regenerating a PDF after updating the title in the pdfs table CREATE TRIGGER generate_pdf_update AFTER UPDATE ON pdfs FOR EACH ROW WHEN (NEW.title IS DISTINCT FROM OLD.title) EXECUTE PROCEDURE trigger_job('generate_pdf'); ``` ``` -------------------------------- ### Build Static Website Source: https://github.com/graphile/worker/blob/main/website/README.md Generates static content for the website into the 'build' directory. This can be served by any static hosting service. ```bash yarn website build ``` -------------------------------- ### Add Job with makeWorkerUtils Source: https://github.com/graphile/worker/blob/main/website/docs/library/queue.md Demonstrates how to use `makeWorkerUtils` to create a `WorkerUtils` instance and add a job to the queue. It's recommended to use `WorkerUtils` as a singleton. Remember to release the instance when done. ```javascript const { makeWorkerUtils } = require("graphile-worker"); async function main() { const workerUtils = await makeWorkerUtils({ connectionString: "postgres:///my_db", }); try { await workerUtils.migrate(); await workerUtils.addJob( // Task identifier "calculate-life-meaning", // Payload { value: 42 }, // Optionally, add further task spec details here ); // await workerUtils.addJob(...); // await workerUtils.addJob(...); // await workerUtils.addJob(...); } finally { await workerUtils.release(); } } main().catch((err) => { console.error(err); process.exit(1); }); ``` -------------------------------- ### Deploy Website Source: https://github.com/graphile/worker/blob/main/website/README.md Deploys the website to GitHub pages. This command is intended for committers and may be automated with GitHub Actions in the future. ```bash yarn website deploy ``` -------------------------------- ### Graphile Worker CLI Options Source: https://github.com/graphile/worker/blob/main/website/docs/cli/run.md Available command-line options for configuring and running Graphile Worker. Use --help for a full list. ```text Options: --help Show help [boolean] --version Show version number [boolean] -c, --connection Database connection string, defaults to the 'DATABASE_URL' envvar [string] -s, --schema The database schema in which Graphile Worker is (to be) located [string] --schema-only Just install (or update) the database schema, then exit [boolean] [default: false] --once Run until there are no runnable jobs left, then exit [boolean] [default: false] --crontab override path to crontab file [string] -j, --jobs number of jobs to run concurrently [number] -m, --max-pool-size maximum size of the PostgreSQL pool [number] --poll-interval how long to wait between polling for jobs in milliseconds (for jobs scheduled in the future/retries) [number] --no-prepared-statements set this flag if you want to disable prepared statements, e.g. for compatibility with some external PostgreSQL pools [boolean] -C, --config The path to the config file [string] --cleanup Clean the database, then exit. Accepts a comma-separated list of cleanup tasks: GC_TASK_IDENTIFIERS, GC_JOB_QUEUES, DELETE_PERMAFAILED_JOBS [string] ``` -------------------------------- ### Runner Options Source: https://github.com/graphile/worker/blob/main/website/docs/library/run.md Configuration options available for `run()`, `runOnce()`, and `runMigrations()` functions. ```APIDOC ## `RunnerOptions` ### Description Options for configuring the Graphile Worker runner. ### Fields - **concurrency** (number) - Optional - The number of jobs to run concurrently. Defaults to the CLI's `--jobs` value. - **noHandleSignals** (boolean) - Optional - If true, the worker will not install signal handlers. You must handle graceful shutdown manually. - **pollInterval** (number) - Optional - The interval in milliseconds for polling for new jobs. Defaults to the CLI's `--poll-interval` value. - **logger** (object) - Optional - A custom logger object. See [`Logger`](./logger.md) for details. - **connectionString** (string) - Optional - A PostgreSQL connection string for the database containing the job queue. One of `connectionString` or `pgPool` must be provided. - **pgPool** (object) - Optional - A `pg.Pool` instance to use. One of `connectionString` or `pgPool` must be provided. - **taskDirectory** (string) - Optional - Path to a directory containing task handler functions. Exactly one of `taskDirectory` or `taskList` must be provided (except for `runMigrations`). - **taskList** (object) - Optional - An object mapping task names to handler functions. Exactly one of `taskDirectory` or `taskList` must be provided (except for `runMigrations`). - **schema** (string) - Optional - The name of the schema containing Graphile Worker tables. Defaults to `graphile_worker`. - **forbiddenFlags** (array) - Optional - An array of flags that are forbidden for jobs. See [Forbidden flags](../forbidden-flags.md). - **events** (EventEmitter) - Optional - A custom Node.js `EventEmitter` instance for receiving worker events. - **noPreparedStatements** (boolean) - Optional - If true, prepared statements will not be used. May slightly impact performance. ``` -------------------------------- ### Run Graphile Worker Tests Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Execute the automated test suite for Graphile Worker. This command also handles database setup. ```bash yarn test ``` -------------------------------- ### Basic Postgres Connection String Source: https://github.com/graphile/worker/blob/main/website/docs/connection-string.md The most common format for specifying a database connection string. ```plaintext postgres://user:password@host:port/dbname ``` -------------------------------- ### Run Tests in Docker Compose Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Command to execute tests within the Docker Compose environment. This ensures tests are run in a consistent setup. ```shell docker compose exec app yarn test ``` -------------------------------- ### PostgreSQL Connection String Format Source: https://github.com/graphile/worker/blob/main/website/docs/cli/run.md Standard format for PostgreSQL connection strings. Placeholders are optional. ```text postgres://[user]:[pass]@[host]:[port]/[databaseName]?[parameter]=[value] ``` -------------------------------- ### Schedule Weekly Email Task Source: https://github.com/graphile/worker/blob/main/website/docs/cron.md Schedules the 'send_weekly_email' task for 4:30 AM UTC every Monday. No special setup is required beyond this crontab entry. ```crontab 30 4 * * 1 send_weekly_email ``` -------------------------------- ### PostgreSQL Error: Relation does not exist Source: https://github.com/graphile/worker/blob/main/website/docs/error-handling.md This harmless error may appear in PostgreSQL logs if the worker schema has not yet been installed. The worker will create the schema automatically. ```sql ERROR: relation "graphile_worker.migrations" does not exist at character 16 STATEMENT: select id from "graphile_worker".migrations order by id desc limit 1; ``` -------------------------------- ### Run Graphile Worker Migrations Source: https://github.com/graphile/worker/blob/main/website/docs/library/run.md Use `runMigrations()` to execute database migrations. This is equivalent to using the CLI with the `--schema-only` option. ```typescript function runMigrations(options: RunnerOptions): Promise; ``` -------------------------------- ### Library Mode Configuration with Precedence Source: https://github.com/graphile/worker/blob/main/website/docs/config.md Demonstrates how direct option properties take precedence over preset settings in library mode. Note the renaming of `concurrency` to `concurrentJobs` between legacy and preset configurations. ```typescript const runner = await runOnce({ taskDirectory: `${__dirname}/tasks`, connectionString: "postgres:///my_db", // Note that the property names don't always line up perfectly between legacy // configuration and the preset options. `concurrency` was renamed to // `concurrentJobs`. concurrency: 2, preset: { worker: { connectionString: "ignored", concurrentJobs: 1, }, }, }); ``` -------------------------------- ### Run Graphile Worker in Library Mode Source: https://github.com/graphile/worker/blob/main/website/docs/contributing.md Use this TypeScript snippet to run Graphile Worker locally by importing its functions. Ensure you have ts-node installed to execute the file. ```typescript import { run, WorkerPreset } from "."; async function main() { const runner = await run({ taskList: { hello: async (_, helpers) => { helpers.logger.info("Hello, world!"); }, }, preset: { extends: [WorkerPreset], worker: { connectionString: "postgres:///my_db", }, }, }); await runner.promise; } main().catch((err) => { console.error(err); process.exit(1); }); ``` -------------------------------- ### Run Graphile Worker Jobs Source: https://github.com/graphile/worker/blob/main/website/docs/library/run.md Use `run()` to start the worker. It runs until stopped by a signal or the `stop()` method. The resolved 'Runner' object provides additional helpers. ```typescript function run(options: RunnerOptions): Promise; ```