@samesake/jobs-pgboss 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +46 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 octalpixel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @samesake/jobs-pgboss
|
|
2
|
+
|
|
3
|
+
**Experimental** — optional pg-boss adapter for `@samesake/server`'s `JobRunner` seam. Not required for 1.0 core publish; integration tests skip unless `PGBOSS_TEST_URL` or `DATABASE_URL` points at direct Postgres (LISTEN/NOTIFY; pooled-only URLs fail).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createMatcher } from "@samesake/server";
|
|
7
|
+
import { createPgBossRunner } from "@samesake/jobs-pgboss";
|
|
8
|
+
|
|
9
|
+
const jobs = await createPgBossRunner({ connectionString: process.env.DATABASE_URL! });
|
|
10
|
+
const matcher = createMatcher({ databaseUrl: process.env.DATABASE_URL!, apiKey: "...", embed, jobs });
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`run()` resolves when the job completes. pg-boss is isolated to this package.
|
|
14
|
+
|
|
15
|
+
**Neon pooled connections:** pg-boss needs a direct Postgres connection for LISTEN/NOTIFY. Use a non-pooled `DATABASE_URL` when possible.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JobRunner } from '@samesake/server';
|
|
2
|
+
|
|
3
|
+
interface PgBossRunnerOptions {
|
|
4
|
+
connectionString: string;
|
|
5
|
+
schema?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function createPgBossRunner(opts: PgBossRunnerOptions): Promise<JobRunner & {
|
|
8
|
+
stop: () => Promise<void>;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
export { type PgBossRunnerOptions, createPgBossRunner };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import PgBoss from "pg-boss";
|
|
4
|
+
async function createPgBossRunner(opts) {
|
|
5
|
+
const boss = new PgBoss({
|
|
6
|
+
connectionString: opts.connectionString,
|
|
7
|
+
schema: opts.schema ?? "pgboss"
|
|
8
|
+
});
|
|
9
|
+
await boss.start();
|
|
10
|
+
const pending = /* @__PURE__ */ new Map();
|
|
11
|
+
const queue = "samesake-jobs";
|
|
12
|
+
await boss.createQueue(queue);
|
|
13
|
+
await boss.work(queue, async (jobs) => {
|
|
14
|
+
for (const job of jobs) {
|
|
15
|
+
const jobId = job.data.jobId;
|
|
16
|
+
if (!jobId) continue;
|
|
17
|
+
const entry = pending.get(jobId);
|
|
18
|
+
if (!entry) continue;
|
|
19
|
+
pending.delete(jobId);
|
|
20
|
+
try {
|
|
21
|
+
const result = await entry.fn();
|
|
22
|
+
entry.resolve(result);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
entry.reject(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
run: (name, payload, fn) => {
|
|
30
|
+
const jobId = randomUUID();
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
pending.set(jobId, { fn, resolve, reject });
|
|
33
|
+
boss.send(queue, { name, payload, jobId }).catch((e) => {
|
|
34
|
+
pending.delete(jobId);
|
|
35
|
+
reject(e);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
stop: async () => {
|
|
40
|
+
await boss.stop({ graceful: true, timeout: 5e3 });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
createPgBossRunner
|
|
46
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@samesake/jobs-pgboss",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "pg-boss JobRunner adapter for @samesake/server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"pg-boss": "^10.1.5",
|
|
23
|
+
"@samesake/server": "^1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@samesake/server": "^1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.5.1"
|
|
30
|
+
}
|
|
31
|
+
}
|