Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous publishing #5

Merged
merged 11 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-kiwis-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pg-task': patch
---

Auto publishing
9 changes: 7 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Create Release Pull Request
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm run ci:publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const manager = createManager({
await manager.start();

// Register a worker for `worker-queue` task queue
const workerId = await manager.work<MyTask>({
const workerId = await manager.register<MyTask>({
queue: 'worker-queue',
async handler(data) {
await Promise.resolve();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: Config = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
collectCoverage: true,
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/__tests__/'],
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/__utils__/'],
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
prettierPath: null,
transformIgnorePatterns: [`node_modules/(?!(?:.pnpm/)?(${esmModules.join('|')}))`],
Expand Down
4 changes: 2 additions & 2 deletions src/manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PostgreSqlContainer, StartedPostgreSqlContainer } from '@testcontainers/postgresql';
import { Pool } from 'pg';
import { cleanupSchema, createRandomSchema } from '../__tests__/db';
import { cleanupSchema, createRandomSchema } from '../__utils__/db';
import { createManager } from './manager';
import EventEmitter, { once } from 'node:events';
import { executeQuery } from './utils/sql';
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('pg worker', () => {
const ee = new EventEmitter();
const promise = once(ee, 'received');

const workerId = await manager.work({
const workerId = await manager.register({
queue: queue,
options: {
poolInternvalInMs: 20,
Expand Down
10 changes: 5 additions & 5 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import type { Pool } from './utils/sql';
const brandSymbol = Symbol('brand');
type WorkerId = number & { [brandSymbol]: 'WorkerId' };

export type WorkerManager = {
export interface WorkerManager {
start(): Promise<void>;
work<TData>(props: QueueWorkerConfig<TData>): Promise<WorkerId>;
register<TData>(props: QueueWorkerConfig<TData>): Promise<WorkerId>;
notifyWorker(workerId: WorkerId): void;
stopWorker(workerId: WorkerId): Promise<void>;
stop(): Promise<void>;
};
}

export type WorkerManagerProperties = {
pgClient: Pool;
Expand Down Expand Up @@ -84,7 +84,7 @@ export const createManager = (properties: WorkerManagerProperties): WorkerManage
return workerId;
}

async function work<TData>(config: QueueWorkerConfig<TData>): Promise<WorkerId> {
async function register<TData>(config: QueueWorkerConfig<TData>): Promise<WorkerId> {
await ensureStarted();
return startWorker(config);
}
Expand All @@ -93,7 +93,7 @@ export const createManager = (properties: WorkerManagerProperties): WorkerManage
start() {
return ensureStarted();
},
work,
register,
notifyWorker(workerId) {
workers.get(workerId)?.notify();
},
Expand Down
2 changes: 1 addition & 1 deletion src/plans.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Pool } from 'pg';
import { createPlans } from './plans';
import { ConfiguredTask, TaskResultStates, Task, SelectedTask, TaskResult } from './task';
import { PostgreSqlContainer, StartedPostgreSqlContainer } from '@testcontainers/postgresql';
import { cleanupSchema, createRandomSchema } from '../__tests__/db';
import { cleanupSchema, createRandomSchema } from '../__utils__/db';
import { executeQuery } from './utils/sql';
import { migrate } from './utils/migrate';
import { createMigrations } from './migrations';
Expand Down
Loading