0.0.2 • Published 11 months ago

pg-task v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

pg-task

A SQS like solution build on top of Postgres and NodeJS.

Usage

npm install pg-task
import { createManager, executeQuery, createPlans, createTaskQueueFactory } from 'pg-task';
import { Pool } from 'pg';

const pool = new Pool({});

const manager = createManager({
  pgClient: pool,
  schema,
});
await manager.start();

// Register a worker for `worker-queue` task queue
const workerId = await manager.register<MyTask>({
  queue: 'worker-queue',
  async handler(data) {
    await Promise.resolve();
  },
});

// enqueue tasks
const plans = createPlans(schema);
const taskFactory = createTaskQueueFactory('worker-queue');
await executeQuery(
  pool,
  plans.enqueueTasks(
    taskFactory([
      {
        data: { somepayload: 'test' },
      },
      {
        data: { somepayload: 'test' },
      },
    ])
  )
);

// On application shutdown
await manager.stop();
0.0.2

11 months ago

0.0.1

11 months ago