Skip to content

Commit

Permalink
Rename + readme example (#3)
Browse files Browse the repository at this point in the history
* Rename + readme example

* Reduce performance requirements

* Fix ci pnpm cache

* Init changeset

* Add ci/cd

* Fix cd

* rename

* Fix cicd
  • Loading branch information
ilijaNL authored Jul 22, 2024
1 parent 92d6402 commit 629d5c2
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 68 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/good-seahorses-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pg-task': patch
---

Add initial version
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: integration

on:
workflow_call:
pull_request:
branches:
- "main"
paths-ignore:
- 'docs/**'
- 'example/**'
- '**/*.md'

jobs:
# Label of the container job
test:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
id: setup-node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8

# See https://github.com/actions/setup-node/issues/641#issuecomment-1358859686
- name: pnpm cache path
id: pnpm-cache-path
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache-path.outputs.STORE_PATH }}
key: ${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: typecheck
run: pnpm run typecheck
- name: test
run: pnpm run test
- name: ✅ Upload coverage to Codecov
uses: codecov/codecov-action@v3
55 changes: 55 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: cicd

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
test:
uses: ./.github/workflows/ci.yml
release:
name: Release
needs: test
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
issues: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
id: setup-node
with:
node-version: 20.x
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8
# See https://github.com/actions/setup-node/issues/641#issuecomment-1358859686
- name: pnpm cache path
id: pnpm-cache-path
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache-path.outputs.STORE_PATH }}
key: ${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-node.outputs.node-version }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create Release Pull Request
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 0 additions & 39 deletions .github/workflows/test.yml

This file was deleted.

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
# pg-task

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

## Usage

```
npm install pg-task
```

```typescript
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.work<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();
```
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export {
type TaskResult,
type TaskResultState,
} from './task';
export {
executeQuery,
type Pool,
type ClientFromPool,
type QueryClient,
type TypedQuery,
type QueryResultRow,
} from './utils/sql';
export default createManager;
4 changes: 2 additions & 2 deletions src/maintaince.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createMaintainceWorker = async (pool: Pool, schema: string, options
// complete this task, and reschedule it in future
await transactionExecutor(plans.resolveTasks([{ task_id: id, result: data, state: TaskResultStates.success }]));
await transactionExecutor(
plans.createTasks(
plans.enqueueTasks(
taskFactory([
{
data: null,
Expand All @@ -73,7 +73,7 @@ export const createMaintainceWorker = async (pool: Pool, schema: string, options

// ensure we try to create the maintaince tasks always
await executor(
plans.createTasks(
plans.enqueueTasks(
taskFactory([
{
data: null,
Expand Down
4 changes: 2 additions & 2 deletions src/manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('pg worker', () => {

await executeQuery(
pool,
plans.createTasks([
plans.enqueueTasks([
{
data: { nosmoke: true },
expireInSeconds: 1,
Expand All @@ -94,6 +94,6 @@ describe('pg worker', () => {
await manager.stop();

// we should not have any pending tasks left
await expect(executeQuery(pool, plans.getAndStartTasks(queue, 100))).resolves.toHaveLength(0);
await expect(executeQuery(pool, plans.popTasks(queue, 100))).resolves.toHaveLength(0);
});
});
Loading

0 comments on commit 629d5c2

Please sign in to comment.